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 - 'will send the info
-
Public Sub sendInfo()
-
'check connection
-
If Not connected Then
-
Throw New Exception("There is no connection to the server.")
-
End If
-
-
'send message
-
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("SERVICE_1")
-
networkStream.Write(sendBytes, 0, sendBytes.Length)
-
-
Dim a As String = "string to be sent for the service_1 sub of the server"
-
-
Dim sendBytes2 As [Byte]() = Encoding.ASCII.GetBytes(a)
-
networkStream.Write(sendBytes2, 0, sendBytes2.Length)
-
End Sub
Code: server - 'will serve a client
-
Private Sub serveClient(ByVal client As TcpClient)
-
'recieve message
-
Dim bytes(client.ReceiveBufferSize) As Byte
-
client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
-
Dim request As String = Encoding.ASCII.GetString(bytes)
-
-
'check needed service
-
-
If matches(request, "SERVICE_1") Then
-
service1(client)
-
ElseIf matches(request, "SERVICE_2") Then
-
service2(client)
-
ElseIf matches(request, "SERVICE_3") Then
-
service3(client)
-
End If
-
End Sub
-
-
-
Private Sub service1(ByVal client As TcpClient)
-
-
Dim bytes(client.ReceiveBufferSize) As Byte
-
client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))
-
Dim clientdata As String = Encoding.ASCII.GetString(bytes)
-
Dim s() As String = clientdata.Split(";")
-
-
If (s.Length < 3) Then
-
MsgBox("string didn't contain ';' zero's recieved")
-
End If
-
-
dosomething(s(0), s(1), s(2))
-
-
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
4 1242 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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 the problem.
Regards,
Sreedhar Bhaskararaju
|
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 paragraph from the standard, I can't determine if this
macro
will always be zero. It would surely be convenient if it is but it
never
states this directly. the "zero or" part, leads me to believe that the
macro
|
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 zero-length string (always returns a zero-length
string when used in a query expression)"
****
How many records are there in FirstTable in which Product Is Null.
SELECT COUNT(*) AS CountofNullProdcut
|
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:
int 08453
should print 08453 if i tried to use printf() on it, and not some octal
number.
|
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 instead of 06.
Thanks a lot.
| |
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 to display the leading zero,
when the first digit is a zero? I'm only dealing with the integer data type.
|
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 30 to connect to the Web Service. That is working fine.
The Problem is, the Web Service returns ordinary string properly , but doesnt return a XML String. Only the values are returned and not the tags.
|
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);
// 100,000.87
which is fine.
|
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.
using System.Windows.Forms;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |