D
Dmitry Akselrod
Sockets Programming Question:
I have two applications. One is a server, one is a client. However, both
listen on certain ports for communication. The server is written in vb.net
(framework v.1.0) and the client is written in vb6 sp5 because vb6 uses far
less resources.
One of the routines in the programming involves the server sending a rather
large xml string to the client:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub sendMessage(ByVal MessageText As String)
Try
If bIsConnected Then
If networkStream.CanWrite Then
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(MessageText)
networkStream.Write(sendBytes, 0, sendBytes.Length)
End If
End If
Catch e As System.Net.Sockets.SocketException
Debug.WriteLine("Connection" & vbCrLf & e.Message)
appLog.WriteEntry("Connection Error" & vbCrLf & e.Message,
EventLogEntryType.Error, 1022)
End Try
Debug.WriteLine("CLIENT>Sending message to: " & sMachineNetBIOSName)
Debug.WriteLine("CLIENT>: " & MessageText)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The client receives the message and writes it to a string, then sends it for
processing:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub axWinsockServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String 'where the data sent by the client will be stored
Call axWinsockServer.GetData(strData, vbString) 'gets the data sent by
the client
Call WSS_ProcessData(strData)
End Sub
Private Sub WSS_ProcessData(ByVal sData As String)
Dim JobCodeRequest As New JobCodeClass
Set JobCodeRequest = ProcessXML.ProcessXML(sData)
If JobCodeRequest.JobID <> 0 Then JobCodeRequestCollection.Add
Item:=JobCodeRequest
Call DisplayPopUp(JobCodeRequest)
axWinsockServer.Close
If (axWinsockServer.State <> sckListening) Then axWinsockServer.Listen
Debug.Print ("Data Received: " & sData)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The function ProcessXML.ProcessXML just processes the xml in the string.
The problem is as follows:
When I run a network monitor to capture the traffic caused by transfer of
this large xml string, I notice that the string is split up in several
packets of 1460 bytes maximum in length. When the client is installed on
some workstations, the client receives the string as a single xml string.
One other workstation, the client receives several strings of 1460 bytes
maximum, thus truncating the xml string and invalidating it in the process.
Since the problem occurs on some workstations, I am guessing the problem is
either network card specific or there is a setting in the registry that
controls the maximum length a socket can send and receive. I am guessing
that Ethernet is optimized to a certain packet length. (BTW, all machines
are XP or Windows 2000, NICs vary).
Should I rewrite my code to analyze the networkstream size and break it down
manually to a max of, let’s say 1000 bytes long? I would have to implement
some kind of continuation method to insure that the strings received on the
client side are concatenated together. Or should I adjust the default send
and receive packet length?
I am guessing I should adjust my code. Has anyone seen this before? Does
anyone have any advice or a good method to implement continuation of
packets?
I suppose that alternately I can ftp the xml file to the client or setup a
web server as part of my code and retrieve the file via simple http get. I
would rather not add this extra code to my software however.
Thank you very much,
Dmitry Akselrod
I have two applications. One is a server, one is a client. However, both
listen on certain ports for communication. The server is written in vb.net
(framework v.1.0) and the client is written in vb6 sp5 because vb6 uses far
less resources.
One of the routines in the programming involves the server sending a rather
large xml string to the client:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub sendMessage(ByVal MessageText As String)
Try
If bIsConnected Then
If networkStream.CanWrite Then
Dim sendBytes As [Byte]() =
Encoding.ASCII.GetBytes(MessageText)
networkStream.Write(sendBytes, 0, sendBytes.Length)
End If
End If
Catch e As System.Net.Sockets.SocketException
Debug.WriteLine("Connection" & vbCrLf & e.Message)
appLog.WriteEntry("Connection Error" & vbCrLf & e.Message,
EventLogEntryType.Error, 1022)
End Try
Debug.WriteLine("CLIENT>Sending message to: " & sMachineNetBIOSName)
Debug.WriteLine("CLIENT>: " & MessageText)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The client receives the message and writes it to a string, then sends it for
processing:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub axWinsockServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String 'where the data sent by the client will be stored
Call axWinsockServer.GetData(strData, vbString) 'gets the data sent by
the client
Call WSS_ProcessData(strData)
End Sub
Private Sub WSS_ProcessData(ByVal sData As String)
Dim JobCodeRequest As New JobCodeClass
Set JobCodeRequest = ProcessXML.ProcessXML(sData)
If JobCodeRequest.JobID <> 0 Then JobCodeRequestCollection.Add
Item:=JobCodeRequest
Call DisplayPopUp(JobCodeRequest)
axWinsockServer.Close
If (axWinsockServer.State <> sckListening) Then axWinsockServer.Listen
Debug.Print ("Data Received: " & sData)
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The function ProcessXML.ProcessXML just processes the xml in the string.
The problem is as follows:
When I run a network monitor to capture the traffic caused by transfer of
this large xml string, I notice that the string is split up in several
packets of 1460 bytes maximum in length. When the client is installed on
some workstations, the client receives the string as a single xml string.
One other workstation, the client receives several strings of 1460 bytes
maximum, thus truncating the xml string and invalidating it in the process.
Since the problem occurs on some workstations, I am guessing the problem is
either network card specific or there is a setting in the registry that
controls the maximum length a socket can send and receive. I am guessing
that Ethernet is optimized to a certain packet length. (BTW, all machines
are XP or Windows 2000, NICs vary).
Should I rewrite my code to analyze the networkstream size and break it down
manually to a max of, let’s say 1000 bytes long? I would have to implement
some kind of continuation method to insure that the strings received on the
client side are concatenated together. Or should I adjust the default send
and receive packet length?
I am guessing I should adjust my code. Has anyone seen this before? Does
anyone have any advice or a good method to implement continuation of
packets?
I suppose that alternately I can ftp the xml file to the client or setup a
web server as part of my code and retrieve the file via simple http get. I
would rather not add this extra code to my software however.
Thank you very much,
Dmitry Akselrod