TCP Server\Client Not working?

BlitzMax Forums/BlitzMax Programming/TCP Server\Client Not working?

Caton(Posted February) [#1]
BlitzPlus\Blitz3D are to slow to create server so I'm using blitzmax and why is it not working?

Server Code


Client Code
tcp=OpenTCPStream("127.0.0.1",1234)
If Not tcp RuntimeError("Couldn't Connect To Server:127.0.0.1":1234")
writeint(tcp,$1257320)
CloseTCPStream tcp



grable(Posted February) [#2]
Because you need to listen to the socket and accept any connections. What you are doing is trying to connect to a remote socket.

Heres how it should look. The server now keeps going after the connection ends, so you can keep connecting.
Global TokenID:Int=$1257320,token:Int, stream:TStream

Print "Server"
Global server:TSocket = CreateTCPSocket ()

Local ok:Int = True
If Not BindSocket(server:TSocket,1234) Then Print "unable to bind port"; ok = false
If Not SocketListen(server) Then Print "unable to listen to socket"; ok = False

If ok then
	Print("Created Server.")
Else
	Print("Couldn't Create Server!")
	End
EndIf


While Not KeyDown(KEY_ESCAPE)
	Local client:TSocket = SocketAccept (server)
	If client Then
		stream = CreateSocketStream(client)
		token:Int=ReadInt(stream)
		Print token
		stream.Close()
	EndIf
Wend

CloseSocket(server)
End