|
Hello all. Long time listener, first time
caller, love the show.
I'm working on an application that has somehow
managed to branch me off into TCP/UDP land. I've noticed some strange
behavior that I'm hoping someone can explain. I've included the sourcecode
for two files below that show whats going on with UDP as an
example.
TCP
Open a TCP connection with
net:=open(":1200","na") then close it with close(net). On my system
(WinXP) I can see that the port is still open as a listening connection even
though the program doesn't reference it anymore. This of course means that
no other program can use that port until the original one has finished
executing. I'm seeing these ports open through my firewall software and
through the use of other programs that try to hit that same port.
UDP
So I switched over to using UDP just to see if the
same behavior happens. Open a server with net:=open(":1200","nau") and
close it with close(net). It closes just fine. Now try to reopen the
server on the same port from the same program execution. No dice.
Also with UDP's send()/receive() commands I notice
another interesting problem. Let's say you have one udpserver listening on
port 1200 and udpclient comes along and using send(":1200","Hi there") send a
packet to the server. Send() seems to open a random outgoing port from the
client and IT LEAVES IT OPEN, much like the TCP problem above.
So I'm hoping that it is just me, but could you all
take a look at the problem and see if I'm crazy? Compile the two programs
seperately then run them in different windows. Press 1 or 2 on the server
to start listening on port 1200 or 1201. On the client press 1 or 2 to
send a hello packet to the appropriate server port, 2 or 3 to tell the server to
stop listening on that port.
********************************Included
file*****************************************************
# UDP Server
# Another intersting problem # On a windows system, pressing 1 the first time will open a listening port # Close that port by telling UDP client to send a goodbye message # Then try to open the same port again global test1,test2
procedure open1() write("Opening Server at port 1200") test1:=open(":1200","nau") | stop("Cannot open server at port 1200") write("Opened server at port 1200") end procedure open2()
write("Opening Server at port 1201") test2:=open(":1201","nau") | stop("Cannot open server at port 1201") write("Opened server at port 1201") end procedure close1()
write("Closing Server at port 1200") x:= close(test1) write("Closed server at port 1200 value of close is "||x) end procedure close2()
write("Closing Server at port 1201") x:= close(test2) write("Closed server at port 1200 value of close is "||x) end procedure
listen1()
open1() write("Listening on port 1200") while packet:=receive(test1) do { case packet.msg of { "quit" : { write("Quit received") write("Packet address is: " ||
packet.addr)
break } default : { write("Packet received:") write("Packet address is: " || packet.addr) write(packet.msg) } } } close1() end procedure
listen2()
open2() write("Listening on port 1201") while packet:=receive(test2) do { case packet.msg of { "quit" : { write("Quit received") write("Packet address is: " || packet.addr) break } default : { write("Packet received:") write("Packet address is: " || packet.addr) write(packet.msg) } } } close2() end procedure main() while command := getch() do {
case command of { "1": listen1() "2": listen2() "q": exit() "h": print_help() } } end procedure print_help()
write("Commands:") write("1: Open server on port 1200") write("2: Open server on port 1201") write("q: Quit") write("h: Help") end **********************************************Included
file***********************************************
# UDP Client
# for use with UDP Server # Demonstrates interesting behavior of send() # send(port_address,message) send a UDP message to port_address # from a random UDP port on the sending system # Using Windows XP (and perhaps other systems) this opens a # random port for listening, but does not close it again global test1,test2
procedure main() while command:=getch() do { case command of { "1": send_hello1() "2": send_hello2() "3": say_goodbye1() "4": say_goodbye2() "q": exit() "h": print_help() } } end procedure send_hello1()
write("sending hello packet to port 1200") send(":1200","hello") end procedure send_hello2()
write("sending hello packet to port 1201") send(":1201","hello") end procedure say_goodbye1()
write("sending quit packet to port 1200") send(":1200","quit") end procedure say_goodbye2()
write("sending quit packet to port 1201") send(":1201","quit") end procedure print_help()
write("Commands:") write("1: Send 'Hello' to port 1200") write("2: Send 'Hello' to port 1201") write("3: Tell server on port 1200 to stop listening") write("4: Tell server on port 1201 to stop listening") write("q: Quit") write("h: Help") end |
- [Unicon-group] TCP/UDP oddities on Windows Phill Gardner
- more heat than light (Re: [Unicon-group] TCP/UDP oddi... Art Eschenlauer
