473,503 Members | 7,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Recieving zero's instead of string through tcp

98 New Member
I work in visual basic,and have 2 forms programs.

One acts as a client, the other as a server. I send two things from client to server;
1: a string describing which service of the server is needed. The server enters a sub based on this string.

2: data needed for the sub the server is in.

However, apparently the second transmission results in 8000+ zero's being recieved instead of the string i sent..

Code: Client

Expand|Select|Wrap|Line Numbers
  1.     'will send the info
  2.     Public Sub sendInfo()
  3.         'check connection
  4.         If Not connected Then
  5.             Throw New Exception("There is no connection to the server.")
  6.         End If
  7.  
  8.        'send message
  9.         Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("SERVICE_1")
  10.         networkStream.Write(sendBytes, 0, sendBytes.Length)
  11.  
  12.         Dim a As String = "string to be sent for the service_1 sub of the server"
  13.  
  14.         Dim sendBytes2 As [Byte]() = Encoding.ASCII.GetBytes(a)
  15.         networkStream.Write(sendBytes2, 0, sendBytes2.Length)
  16.     End Sub

Code: server
Expand|Select|Wrap|Line Numbers
  1.     'will serve a client
  2.     Private Sub serveClient(ByVal client As TcpClient)
  3.         'recieve message
  4.         Dim bytes(client.ReceiveBufferSize) As Byte
  5.         client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
  6.         Dim request As String = Encoding.ASCII.GetString(bytes)
  7.  
  8.         'check needed service
  9.  
  10.         If matches(request, "SERVICE_1") Then
  11.             service1(client)
  12.         ElseIf matches(request, "SERVICE_2") Then
  13.             service2(client)
  14.         ElseIf matches(request, "SERVICE_3") Then
  15.             service3(client)
  16.         End If
  17.     End Sub
  18.  
  19.  
  20.     Private Sub service1(ByVal client As TcpClient)
  21.  
  22.         Dim bytes(client.ReceiveBufferSize) As Byte
  23.         client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
  24.         Dim clientdata As String = Encoding.ASCII.GetString(bytes)
  25.         Dim s() As String = clientdata.Split(";")
  26.  
  27.         If (s.Length < 3) Then
  28.             MsgBox("string didn't contain ';' zero's recieved")
  29.         End If
  30.  
  31.         dosomething(s(0), s(1), s(2))
  32.  
  33.     End Sub
so I repeat, the server does recieve the string "SERVICE_1" correctly, but it does NOT recieve the needed string in service1 sub. What am I doing wrong?

(when I putted breakpoints on all lines, and ran through them, apparently it did recieve it correctly, but it does not do that without breakpoints)

Thanx
Aug 3 '08 #1
4 1234
Gangreen
98 New Member
*bump*
someone, please?
Aug 4 '08 #2
Plater
7,872 Recognized Expert Expert
I would say that your first read on the server side is probably reading in BOTH messages, leaving nothing for the 2nd read to read.
If you were doing proper sending and receiving, you would be checking the "actual number of bytes read/written" and validating you have read the correct ammount.
Aug 4 '08 #3
Gangreen
98 New Member
I've put a breakpoint only on the line right after the server read the string.

Instead of it being: "SERVICE_1" , it was "SERVICE_1.
(without the ending parenthesis) What's up with that?

Do you have an example of a better way of doing this?
Aug 5 '08 #4
Plater
7,872 Recognized Expert Expert
Well I would start by using delimenators or come up with some other messaging format.
With a deliminator you can tell your first read to only read up until the deliminator charater(s). Making sure the data is still there following it.

Also, you tell the send and receive functions to send/receive the size of their buffer, and not the size of data you actually want, try only sending as many bytes as are in your byte[] and see if that helps.
Aug 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3032
by: shreedhar | last post by:
If I try to delete a record from my table which is giving following error Warning: PostgreSQL query failed: ERROR: pg_atoi: zero-length string in /xxx/database.inc on line 73 What might be...
25
15583
by: Mantorok Redgormor | last post by:
Finally, control is returned to the host environment. If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. beyond this...
10
4560
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
33
2328
by: gk245 | last post by:
I mean, anything that follows a 0 is automatically turned into a octal number. I want to have a integer variable that will hold numbers as integers even if they begin with a zero. for example:...
15
8027
by: angellian | last post by:
Sorry to raise a stupid question but I tried many methods which did work. how can I conserve the initial zero when I try to convert STR(06) into string in SQL statment? It always gives me 6...
3
1033
by: Candace | last post by:
I have a program that performs calculations and displays a four digit number. Sometimes the calculation results in a number like 0854, but my program displays it as 854. How can I force the program...
1
1102
by: Adi2903 | last post by:
Hi I have a ASP Application interacting with a C#.Net Web Service. The ASP Application recieves the XML from Web Service and uses XSLT to transform and display the output. The ASP uses SOAP...
3
3893
by: hharry | last post by:
Hello All, I am using the following to format numbers precise to 2 decimal places with thousand separators: Double number = 100000.87; string MyString = String.Format("{0:0,0.00}", number);...
7
13613
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. ...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.