****紧急:高分请教,请SOCKET高手出手帮忙呀(顶帖有分)******
为什么我的SOCKET侦听的时候,发送了3个信息或者2个信息到端口,我只能收到其中的一个信息呢?帮看看有什么不妥的么?
能附带帮忙回答一下,如何让服务器主动给下面的客户端,发送信息呢?是不是要一直保持着Accept()出来的端口呢?
SOCKET没有搞过,希望高手帮忙呀!
我的服务器端侦听端口的部分代码如下:
我是使用BackgroundWorker 打开和侦听端口的:
private void FORM1_Load(object sender, EventArgs e)
{
BackgroundWorker bwReceiver = new BackgroundWorker();
bwReceiver.DoWork += new DoWorkEventHandler(ListenLocalHost1);
bwReceiver.RunWorkerAsync();
}
private void ListenLocalHost1(object sender, DoWorkEventArgs e)
{
BeginListenClient(3231);
}
private void BeginListenClient(int iPort)
{
try
{
int port = iPort;
string host = "192.168.16.161 ";
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket类
s.Bind(ipe);//绑定端口
s.Listen(0);//开始监听
CommandDataExchange_New.CreatErrorFile( "开始侦听端口: " + iPort.ToString());
Socket clientSocket = null;
while (true)
{