473,320 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Sockets

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


Nov 20 '05 #1
9 3053

"Dmitry Akselrod" <dm*****@ddi.com> wrote in message
news:vq************@corp.supernews.com...

Please do not crosspost questions between .NET and non-.NET groups. The
*.vb.* groups are for VB6 and earlier. The *.dotnet.* groups are
for--surprise!--.NET.
Nov 20 '05 #2
"Dmitry Akselrod" <dm*****@ddi.com> wrote in message news:vq************@corp.supernews.com...
Sockets Programming Question:

The server is written in vb.net
(framework v.1.0) and the client is written in vb6
Doesn't matter. The Server can be a Mac and the Client can be my
XBox. That's the beauty of standardized network protocols.

<Snip a ton of code>
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.
The problem is because when you send data it is actually chopped up
and sent as packets, and then reconstructed at the destination. In the
case of VB6 with the winsock control, you may need to keep grabbing
chunks of data and concatenating it together to get the full packet.

The way I handle this is to first send a message telling how large
the data will be. I then keep reading from the socket stream until
I've read that many bytes.
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.
No. Most likely the reason it happens sometimes is due to the network
bandwidth. The first time I hit this problem was when I was testing an
app where the client and server were on the same machine and it worked
great, but as soon as I used the server on a different machine this issue
arose.
I would have to implement
some kind of continuation method to insure that the strings received on the
client side are concatenated together.


Bingo.

--
Andrew Faust

Where are we going and why am I in this handbasket?
Nov 20 '05 #3
In article <vq************@corp.supernews.com>, Dmitry Akselrod wrote:
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.


<snip>

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


Dmitry

What your experiencing is the normal behavior of TCP. TCP is a
streaming protocol. Data is broken into chunks and then reassembaled on
the other end.

Generally when sending data back and forth across tcp socket you need to
have some sort of end of stream marker - which for text is commonly a
CR+LF combo - or know exactly how many bytes you are to recieve.

So, assuming a text stream with CR+LF as a terminator, the recieve would
do something like:

1. receive data
2. append to buffer
3. did I recieve my terminator?
a. Yes - Exit
b. No - goto 1

HTH
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #4
I apologize for any inconvenience.
"Jeff Johnson [MVP: VB]" <i.***@enough.spam> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...

"Dmitry Akselrod" <dm*****@ddi.com> wrote in message
news:vq************@corp.supernews.com...

Please do not crosspost questions between .NET and non-.NET groups. The
*.vb.* groups are for VB6 and earlier. The *.dotnet.* groups are
for--surprise!--.NET.

Nov 20 '05 #5

"Andrew Faust" <af****@aradyme.com.REMOVE> wrote in message
news:e2**************@TK2MSFTNGP12.phx.gbl...
"Dmitry Akselrod" <dm*****@ddi.com> wrote in message news:vq************@corp.supernews.com...
Sockets Programming Question: 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.
The problem is because when you send data it is actually chopped up
and sent as packets, and then reconstructed at the destination. In the
case of VB6 with the winsock control, you may need to keep grabbing
chunks of data and concatenating it together to get the full packet.

The way I handle this is to first send a message telling how large
the data will be. I then keep reading from the socket stream until
I've read that many bytes.


Excellent! That's what I was looking for, thank you for the advice!

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.


No. Most likely the reason it happens sometimes is due to the network
bandwidth. The first time I hit this problem was when I was testing an
app where the client and server were on the same machine and it worked
great, but as soon as I used the server on a different machine this issue
arose.


I think that you have a point there. After further analysis, I determined
that the workstations that are physically further away from the server
applications are the ones having most of the trouble.

Thanx again,

Dmitry
Nov 20 '05 #6

"Tom Shelton" <to*@mtogden.com> wrote in message
news:Oz*************@tk2msftngp13.phx.gbl...
In article <vq************@corp.supernews.com>, Dmitry Akselrod wrote:
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.

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.

Dmitry

What your experiencing is the normal behavior of TCP. TCP is a
streaming protocol. Data is broken into chunks and then reassembaled on
the other end.

Generally when sending data back and forth across tcp socket you need to
have some sort of end of stream marker - which for text is commonly a
CR+LF combo - or know exactly how many bytes you are to recieve.

So, assuming a text stream with CR+LF as a terminator, the recieve would
do something like:

1. receive data
2. append to buffer
3. did I recieve my terminator?
a. Yes - Exit
b. No - goto 1


Tom, thanx. I will look for for CR and LF characters.
Nov 20 '05 #7
In article <vq************@corp.supernews.com>, Dmitry Akselrod wrote:

"Tom Shelton" <to*@mtogden.com> wrote in message
news:Oz*************@tk2msftngp13.phx.gbl...
In article <vq************@corp.supernews.com>, Dmitry Akselrod wrote:
> 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.
>
> 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.
>

Dmitry

What your experiencing is the normal behavior of TCP. TCP is a
streaming protocol. Data is broken into chunks and then reassembaled on
the other end.

Generally when sending data back and forth across tcp socket you need to
have some sort of end of stream marker - which for text is commonly a
CR+LF combo - or know exactly how many bytes you are to recieve.

So, assuming a text stream with CR+LF as a terminator, the recieve would
do something like:

1. receive data
2. append to buffer
3. did I recieve my terminator?
a. Yes - Exit
b. No - goto 1


Tom, thanx. I will look for for CR and LF characters.


Dmitry,

Only do that if that is how your string is terminated... I was just
pointing out that CR+LF is the common choice, but it can just as easily
(and I've seen it done) be a null byte. This isn't something that is
defined by the TCP layer, but by the protocol that you develope on top
of TCP.

HTH
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #8
"Dmitry Akselrod" <dm*****@ddi.com> wrote in message
news:vq************@corp.supernews.com...
Sockets Programming Question:
[...] One of the routines in the programming involves the server sending a rather large xml string to the client: [...]
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).

[...]

It's quite normal to expect TCP/IP at this level of the protocol stack to
chop up your data into packets of various sizes and spit them down the wire.
This is why most (estabilished) TCP internet protocols you see base their
"send complete" or packet terminators as unique values at the end.. for
example, let's take POP3.

When you request an email from a POP3 server you issue the command: RETR
<msg number> <CRLF>

The server doesn't give a fig for what the packet sizes are, nor does it
use/assume fixed lengths for the commands you send it. It simply waits for
the <CRLF> and then parses the info leading up to it.

Assuming you requested a valid email, the reply may be much larger and over
many lines. Clearly, terminating on <CRLF> is a no-no. So instead it
terminates on <CRLF>.<CRLF>, and it guarantees (by munging the email*) that
the only place this particular byte sequence will occur is to signal that it
has finished sending the email to the client, which could have been
streaming MBs of data in thousands of packets until that point.

Because POP3 is over a TCP stream, other IP issues such as packet integrity
and sequencing are handled for you (not so with UDP, you're on your own), so
really only controlling the "language" of the protocol is of concern. Using
a method such as that described above, or one like that used by HTTP POST
where it indicates in a "header" at the beginning of the transmission how
big the following chunk of data is going to be, are amongst the most common
ones for handling varying length communications.

Either way you will not be able to force/guarantee the packet size and will
need to keep concatenating the data you receive in chunks at the other end
until you've reached your limit/marker to signal the end.

Trying to work against the TCP/IP configuration and trying to force the MTU
and other properties to manage your data in a single chunk is actually just
more likely to degrade network performance (not just for your app, but for
all other network communications over the same wire) and/or cause network
failures. These days, the self-tuned values in use by the devices and
drivers that deal with network protocols are best left alone.

Regards,
Nick

* If it detects a <CRLF>.<CRLF> sequence in the email anywhere, to prevent
premature termination by the receiving app I believe it just adds a space
after the period, like this: <CRLF>.<SPACE><CRLF>

Or maybe it was a space before the period? I'm too lazy to look it up now,
I'm sure it is one or the other though heh. Just remember if you use a
similar mechanism yourself, that it is something you would have to take into
consideration also.
Nov 20 '05 #9
Thanx Everyone for all your suggestions and explanations. I really
appreciate it.

I ended up appending two End Of Transmission ASCII characters (Chr(4)) to
the ends of all transmissions. I haven't had any problems since. Since I
was parsing the transmissions with an xml parser, I had to remove the extra
couple of characters before doing so of course.

Thanx again,

Dmitry
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
0
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up...
3
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on...
1
by: Adam Clauss | last post by:
I am (attempting) to move an existing socket application to use raw sockets. Right now, my application is essentially a port forwarder. Upon receiving a connection, it will open a connection to...
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
7
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the output.. ../../../sockets.cpp: In constructor...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.