Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
C#
public void receive_send(object obj) {
           Socket sk = (Socket)obj;
           while (true) {
               Byte[] buffer = new Byte[1024];
               int recv = sk.Receive(buffer);
               foreach (Socket temp in listClient)
                   temp.Send(buffer, buffer.Length, SocketFlags.None);
           }
       }



I looked at an app chat, above code is on server.
I have some problems about send and receive method.

First, Receive means "receives data from a bound System.Net.Sockets.Socket into a receive buffer", so sk.Receive(buffer) mean receive data from sk ?
have any differences between it and ReceiveFrom method?

Equal problem with Send?
temp.Send means "send data to temp" ?

Here is link to all code.
https://www.dropbox.com/s/6z1u91hoh5utdb9/server.txt[^]
https://www.dropbox.com/s/wh0s7wml4aol7ze/client.txt[^]

Tks to read.
Posted
v2

1 solution

Quote:
First, Receive means "receives data from a bound System.Net.Sockets.Socket into a receive buffer", so sk.Receive(buffer) mean receive data from sk ?

No, not quite right. It means "receive data from sk, which is listening at a certain ip and port on your computer".

Quote:
have any differences between it and ReceiveFrom method?

Receive:http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receive.aspx[^]
ReceiveFrom: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.receivefrom.aspx[^]

Quote:
Equal problem with Send?
temp.Send means "send data to temp" ?

Nope. It means that you give the data to the object called "temp" and afterwards the object sends the data to a certain IP and a certain port which you have specified before.
 
Share this answer
 
Comments
thangnv249 15-Apr-13 9:33am    
thank you, i got that.
Marco Bertschi 15-Apr-13 10:17am    
You're welcome, I am glad that I was able to help you.

cheers,
Marco

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900