Sockets
BlitzMax Forums/BlitzMax Programming/Sockets
| ||
| I'm having troubles making two programs communicate with sockets. I'm trying two programs, a client and a server. Here is the code i'm using. They perfectly work, but when i close them their executables are still running. Could someone help me? Client:
Global port:Long=1125
stream : TSocketStream = TSocketStream.CreateClient("localhost", port)
If Not stream Then
RuntimeError("Error creating socket")
EndIf
If Not stream End
stream.WriteLine "GET / HTTP/1.1~r~n"
stream.WriteLine "hi~r~n"
stream.WriteLine "Host: 127.0.0.1~r~n"
stream.WriteLine "~r~n"
While Not Eof( stream )
'If Not stream.ReadLine() Exit
Print Stream.Readline()
Wend
stream.close()
stream = Null
End
[/CODE]
Server:
[CODE]
Global receive:TSocket = CreateTCPSocket()
Global port:Long=1125
If (Not BindSocket(receive, port))
Print("Error. Someone might already be using port"+port+".")
End
End If
Print "Server started."
SocketListen(receive)
While True
Local clientSock:TSocket = SocketAccept(receive, 0)
If (clientSock <> Null)
Print("Client "+DottedIP(SocketRemoteIP(clientSock))+" connected!")
Local clientStream:TSocketStream = CreateSocketStream(clientSock)
Local line:String = ReadLine(clientStream)
Print(line)
FlushStream(clientStream)
'CloseStream(clientStream)
'CloseSocket(clientSock)
EndIf
Wend
CloseSocket(receive)
CloseSocket(clientSock)
'CloseStream(clientStream)
'CloseSocket(clientSock)
End
Another problem is that the client can only send a line of text, and then nothing get sent. Please someone help me. |
| ||
| Ok. I found the problem and corrected. The first problem was because i wasn't in graphics mode, and KEY_ESCAPE didn't worked for this reason. The second was simply corrected doing while not eof(stream). |