program crash when serverconnection is interrupted

schimanski

Well-Known Member
Licensed User
Longtime User
Hello!

I have a problem with a server-connection. When the server-connection is interrupted, the application will crash. Only the task-manager can end the program. The Errorlabel can' catch this crash. The lines below are my source-code to get the data from the server:

'Create the server-connection, when button is clicked'
Sub Button4_Click
ErrorLabel(noconnection)
WaitCursor(true)
client.New1 'init Client-Objekt'
IP_Adresse=textbox18.Text
Port_Nummer=textbox19.Text
Client.Connect (IP_Adresse,Port_Nummer)

If timer2.Enabled=false Then timer2.Enabled = true
WaitCursor(false)
Return
noconnection:
..
End Sub

'Takes the data from the server'
Sub Timer2_Tick
ErrorLabel(connectionbreak)
if ComboBox2.SelectedIndex = 1 then
If client.DataAvailable=true Then
Image4.LoadPicture("IconDaten1.bmp")
filestream.New1(client.GetStream,false)
GPS_Server.GPSStream(filestream.ReadString)
Else
Image4.LoadPicture("IconDaten2.bmp")
End If
else
if client.DataAvailable=true then filesstream.Readstring
End If
Return

connectionbreak:
..
client.close
End Sub


thanks....:sign0085:
 

agraham

Expert
Licensed User
Longtime User
I can't see why this would lock up, but is is a bit inefficient in that it New1's a filestream and loads a picture for every bit of data received. You may want to look at this code http://www.b4x.com/forum/showthread.php?t=1130 that implements both a server and a client. I've tried killing the server and the client doesn't to lock up waiting for receive, it never sees any data available. It throws an error if the client tries to send after the server stops unexpectedly.

Depending upon the implementation of the server and the TCP/IP stacks at each end what to the server seems a single send can arrive as several packets at the client. You are not assuming that a complete message always arrives intact as a single message are you?
 
Top