Is someone able to replicate my problem (network)?
Posted: Mon Feb 14, 2011 5:23 pm
Hi,
I create a small server (cancel with ESC). Please compile as console-app.
Additional, there is a small client application needed. This one creates a connection, sends something, waits for the result, validates the result and closes the connection. And this in a endless loop.
This is the small client (cancel with ESC). Please compile as console-app.
At the beginning, everything works fine. After a while, the client responses "no connection possible!". This is getting more and more bad. It does not help to restart the client. I need to restart the server to fix this.
What is my misstake? Is there an error in the code? I do not manage to pass my performance-tests because of this error.
After a while, sometimes, the server does not accept connections. Is there something wrong? Did I miss something? Something to cleanup?
Kukulkan
I create a small server (cancel with ESC). Please compile as console-app.
Code: Select all
; Server
InitNetwork()
OpenConsole()
PrintN("Server started!")
ServerID.l = CreateNetworkServer(1, 6002, #PB_Network_TCP)
While Quit.b = #False
; ####### check network data #######
SEvent.l = NetworkServerEvent()
CID.l = 0
If SEvent.l <> 0
CID.l = EventClient()
EndIf
Select SEvent.l
Case #PB_NetworkEvent_Connect ; ####### new client #######
; PrintN("Connect " + Str(CID.l))
Case #PB_NetworkEvent_Data
; PrintN("Data " + Str(CID.l))
*NetworkBuffer.l = AllocateMemory(8192) ; 8 KB Puffer for Server
ReceivedContent.s = ""
length.l = ReceiveNetworkData(CID.l, *NetworkBuffer.l, 8192)
If length.l > 0
ReceivedContent.s = PeekS(*NetworkBuffer.l, length.l)
EndIf
FreeMemory(*NetworkBuffer.l)
If ReceivedContent.s <> ""
; calculate something
PrintN("Did some job. " + FormatDate("%yyyy/%mm/%dd %hh:%ii:%ss", Date()))
For x.l = 1 To 50000
e.l = Random(1000)
Next
SendNetworkString(CID.l, "Result is aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbccccccccccccccc")
CloseNetworkConnection(CID.l)
EndIf
Case #PB_NetworkEvent_Disconnect
EndSelect
If Inkey() = Chr(27): Quit.b = #True: EndIf
Delay(1)
Wend
CloseNetworkServer(1)
PrintN(" ")
PrintN("FINISHED SERVER")
EndThis is the small client (cancel with ESC). Please compile as console-app.
Code: Select all
; Client
lngTimeoutSeconds.l = 5
InitNetwork()
OpenConsole()
PrintN("Client started!")
While Quit.b = #False
Conn.l = OpenNetworkConnection("127.0.0.1", 6002)
If Conn.l <> 0
; send request
SendNetworkString(Conn.l, "Hey, do some job...")
StartTime.l = ElapsedMilliseconds() + (lngTimeoutSeconds.l * 1000)
Result.s = ""
Repeat
*NetworkBuffer.l = AllocateMemory(8192) ; 8 KB Puffer for Server
length.l = ReceiveNetworkData(Conn.l, *NetworkBuffer.l, 8192)
If length.l > 0
Result.s = Result.s + PeekS(*NetworkBuffer.l, length.l)
EndIf
FreeMemory(*NetworkBuffer.l)
Until Len(Result.s) > 2 Or ElapsedMilliseconds() > StartTime.l Or Quit.b = #True
If ElapsedMilliseconds() > StartTime.l
PrintN("TIMEOUT!")
EndIf
CloseNetworkConnection(Conn.l)
If Result.s <> "Result is aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbccccccccccccccc"
PrintN("FAILED!")
EndIf
Else
; no connection possible!
PrintN("no connection possible!")
EndIf
Delay(1)
If Inkey() = Chr(27): Quit.b = #True: EndIf
Wend
PrintN(" ")
PrintN("FINISHED CLIENT")
CloseConsole()
EndWhat is my misstake? Is there an error in the code? I do not manage to pass my performance-tests because of this error.
After a while, sometimes, the server does not accept connections. Is there something wrong? Did I miss something? Something to cleanup?
Kukulkan