BNet / Networking question

BlitzMax Forums/BlitzMax Module Tweaks/BNet / Networking question

QuietBloke(Posted 2005) [#1]
Not sure if this is BNet related or network related in general.
I am just playing around writing a chat server to practice my networking skills and I have come across a problem... or at least i think it is a problem.

The clients connect using Telnet ( Im just using the one that comes with Windows XP ).
When the user types the /bye command my server closes the stream using the closeTCPStream. I thought when I do this the telnet app will report that the connection to the host has been lost but it does not.
This seems fair enough I guess.. maybe the telnet client doesnt know the connection is dropped.
But when my Chat server program ends the telnet program(s) then quit with a message saying the connection to the host is lost.
So.. how does it know it is lost when the server program ends but it doesnt know it is lost when I close the stream ?
Does this mean that even though I have closed the stream it has not in fact really closed ?

Great package BTW... It seems very easy to use and it helps I can use the BlitzPlus help pages to figure out what to do :)


QuietBloke(Posted 2005) [#2]
OK.. so no replies...
As I didnt know whether the problem lied with my understanding or with BNet I went back to blitzPlus and wrote a simple app to see if I get the same results.

Graphics 640,480,0

main ()
End

Function main()
	Local svrGame
	Local strStream
	
	
	svrGame = CreateTCPServer(6000)
	
	While Not KeyHit(1)
		strStream = AcceptTCPStream(svrGame)
		
		If strStream Then
			WriteString(strStream,"Im busy. Come back later" )
			CloseTCPStream(strStream)
		End If

		Delay 500
	Wend
	
End Function


When I run the code in BlitzPlus and Telnet to it I get the Come back later message and then the 'Connection to Host Lost'comes up and telnet quits.
When I run the code in BlitzMax using BNet I get the Come back later message but I can carry on typing away Telnet. It is as if the connection is still there.

So it appears it is a problem with BNet. Ill try and find the problem in the code myself but if you are reading this Vertex and you could fix it I'd really appreciate it. Or in fact if anyone could take a look Id appreciate it.


Vertex(Posted 2005) [#3]
Hi!
Can you say, how I can use Telnet? I just write open 127.0.0.1:6000 or 127.0.0.1 and Telnet tells me, that Telnet can't connect to this server.

But I don't know, why no connection abort in your tests.
   Function CloseTCPStream(tClient:TTCPClient)
      If tClient = Null Then Return
      tClient.Close()
   End Function


   Method Close()
      s_shutdown(iSocket, 2)
      s_closesocket(iSocket)
      iSocket = INVALID_SOCKET
   End Method


I use shutdown to remove send- und receivefunction from this socket and close this socket with all connections.

Have You test to close the server too?

cu olli


QuietBloke(Posted 2005) [#4]
The telnet command caught me out too. The syntax is either from the command line

Telnet 127.0.0.1 6000

or within Telnet

o 127.0.0.1 6000

Im not at home at the moment so I cannot test what happens when I close the Server but I will try it tonight.

Thank you for taking a look


Vertex(Posted 2005) [#5]
Hi!
I've found the bug. AcceptTCPClient returns TTCPStream, but CloseTCPStream needs TTCPClient. "If tClient = Null Then Return" was every active, so no shutdown and no closesocket can called.
Now it does work fine :)
http://vertex.art-fx.org/bnet.zip

Thx for interesting!
cu olli


QuietBloke(Posted 2005) [#6]
woohoo !... thank you so much Vertex.
Ill try it out tonight.

me -> 100% happy... its perfect !


Jeroen(Posted 2005) [#7]
Works very well!
Good job Vertex!

A next step could be to add some stuff BlitzPlay has, like kicking/banning players, team support, some sort of Gnet functionailty...