Hi :D,
I am sending data to server via TCP IP Connection. I am using a continuous loop at the server end - that accepts new clients and while streams can be read, it reads data stream.
The data is sent from the client with 2 leading bytes of data that represent the size of the packet of data sent and type of data.
My question is: how do I retrieve the size of the data packet and then check that this amount of data has been retrieved?
Thanks :)
Q
PS:
Client: -
Dim Enc As Encoding = Encoding.GetEncoding("utf-32")
-
-
Dim UserNameText As String = UserName.Text
-
-
Dim UserNameTextLength = Enc.GetByteCount(UserNameText)
-
-
Dim UserNameByte As Byte() = New Byte(UserNameTextLength + 1) {}
-
Enc.GetBytes(UserNameText, 0, UserNameText.Length, UserNameByte, 2)
-
-
UserNameByte(0) = 99 'Packet Size
-
-
UserNameByte(1) = 88 'Packet Type
-
-
Dim Client As New TcpClient("192.168.1.65", 65535)
-
-
Dim Stream As NetworkStream = Client.GetStream
-
-
Dim Chars As Char() = Enc.GetChars(UserNameByte)
-
-
MessageBox.Show(Chars)
-
-
Stream.Write(UserNameByte, 0, UserNameByte.Length)
-
Server: I would like to retrieve the packet size and then retrieve that size of data. -
While Listener.Pending = False
-
Client = Listener.AcceptTcpClient()
-
Dim Stream As NetworkStream = Client.GetStream()
-
-
While Stream.CanRead
-
-
Dim UserNameByte(Client.ReceiveBufferSize) As Byte
-
Stream.Read(UserNameByte, 0, CInt(Client.ReceiveBufferSize))
-
-
Dim UserNameStringByte(Client.ReceiveBufferSize - 2) As Byte
-
-
Array.Copy(UserNameByte, 2, UserNameStringByte, 0, UserNameByte.Length - 2)
-
-
Dim Enc As Encoding = Encoding.GetEncoding("utf-32")
-
Dim Chars As Char() = Enc.GetChars(UserNameStringByte)
-
-
MsgBox(Chars)
-
-
End While
-
-
End While
-
1 4127 Plater 7,872
Recognized Expert Expert
Assuming your server is at the start of waiting for a message.
Read in 2 bytes. Convert that into the correct number. Check to see if that many bytes is available to read. Based on that result, either read or continue to wait?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew |
last post by:
Hello,
Is it possible for a file position indicator of an input stream to be
greater than the size of a file? And if so could this cause fgetc to
somehow write to the file? For example is it...
|
by: QQ |
last post by:
Hello I am a newbie on network programming.
I am trying to receive a packet
if((numbytes = recvfrom(udp_fd1, buf, MAXLEN-1, 0,(struct
sockaddr*)®ister_addr, &addr_len))==-1){
fprintf(stderr,...
|
by: David Sworder |
last post by:
Hi,
I'm writing an application in which a client (C#/WinForms) and server
(C#/service) interact with one another. The client establishes a "session"
with the server but for scalability reasons...
|
by: Nick |
last post by:
I have found a class that compresses and uncompresses data but need
some help with how to use part of it below is the deflate method which
compresses the string that I pass in, this works OK. At...
|
by: junk5 |
last post by:
Hi
I need to read raw 16 bit data from a file, where the first byte is the
most significant byte of the first data value and the second byte is
the least significant byte of the first data value...
| |
by: owolablo |
last post by:
Hi,
I'm writing a program that sends 1500 bytes of data at once, from the
client to the server. However, the packet is broken down into 3
different segments of 500 each before getting to the...
|
by: rattan |
last post by:
I want a specific packet format for packet exchange between a client
server across the network. For example frame format
as a python class could be:
class Frame:
def __init__(self, buffer=None,...
|
by: Diego F. |
last post by:
Hello. I'm having problems reading data from a socket. In my test, I see the
maximum size to get data from the socket is 8192 bytes.
In my tests, if I send less that 8192, the readen data have...
|
by: Zytan |
last post by:
This may be the dumbest question of all time, but...
When I set the packet size, does it mean ALL packets are that size, no
matter what? Let's say the packet size is 8KB, and I send a 5 byte...
|
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,...
|
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...
| |
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |