SocketFlags.None does not work

  • Thread starter Thread starter Hasan O
  • Start date Start date
H

Hasan O

Hi ,
maybe it is not the right place to ask .

Hi , i have problem about sending data over socket . It waits for another
socket.send

// str = Encoding.ASCII.GetBytes("hello");

socket.Send(str,0,str.Length,SocketFlags.None);

socket.Receive(strincome,0,socket.Available,SocketFlags.None); // return
"hello to you "

// str =Encoding.ASCII.GetBytes( "how_are_you ");

socket.Send(str,0,str.Length,SocketFlags.None);

socket.Receive(strincome,0,socket.Available,SocketFlags.None);// return
"fine"



it sends like this "hellohow_are_you" , but it is wrong , how can i solve it
?
 
Hasan O said:
// str = Encoding.ASCII.GetBytes("hello");

socket.Send(str,0,str.Length,SocketFlags.None);

socket.Receive(strincome,0,socket.Available,SocketFlags.None); // return
"hello to you "

// str =Encoding.ASCII.GetBytes( "how_are_you ");

socket.Send(str,0,str.Length,SocketFlags.None);

socket.Receive(strincome,0,socket.Available,SocketFlags.None);// return
"fine"



it sends like this "hellohow_are_you" , but it is wrong , how can i solve
it

You are not sending the null byte that terminates the string "hello". If all
your transmissions are strings you will need to add 1 to the length of
everything that you send. Of course, then the receiver has to make the same
assumption either create and array of strings or separate one from the next
by some delimiter.

Regards,
Will
 
Back
Top