blob: 4f35ec57d0d836ad01cd9d5d8ead72bcb6ed91b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#!/usr/bin/env ruby1.8
require 'socket'
GPS_SERVER_IP = "192.168.2.1"
GPS_SERVER_PORT = 5445
MODE = :client
PROTOCOL = :tcp
def tcp_read(sock)
loop {
data = sock.readline()
puts data.inspect
}
end
if PROTOCOL == :tcp
if MODE == :client
sock = TCPSocket.new(GPS_SERVER_IP, GPS_SERVER_PORT)
tcp_read(sock)
sock.close
else
serv = TCPServer.new(GPS_SERVER_PORT)
sock = serv.accept
tcp_read(sock)
sock.close
end
elsif PROTOCOL == :udp
sock = UDPSocket.new
sock.bind('0.0.0.0', GPS_SERVER_PORT)
loop {
begin
msg, sender = sock.recvfrom(1024)
rescue Errno::EAGAIN, Errno::EWOULDBLOCK => e
puts "recvfrom error: #{e.class}: #{e}"
next
end
puts msg.inspect
}
end
|