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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top