none
socket.Connect問題 RRS feed

  • 問題

  • 比如我Server要傳訊息給三個Client分別為下面這三個,我是用String[]儲存UserIP
    那我主要問題是當我傳給第一個時候對方是連線的,但是我傳給第二個時候對方要是"離線"的話就會出錯了,那我下面程式要怎麼改才能判斷對方是否在線或是離線?

    1.192.168.10.1
    2.192.168.10.2
    3.192.168.10.3   

    foreach (string CurrentIP in UserIP)
                                    {

                                        IPAddress myIP = IPAddress.Parse( CurrentIP );

                                        IPEndPoint myEP = new IPEndPoint(myIP, 1234);

                                        Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                        TcpListener myListener = new TcpListener(myEP);

                                        socket.Connect(myEP);

                                        byte[] recv = new Byte[256];
                                        recv = Encoding.UTF8.GetBytes("hello");
                                        socket.Send(recv, 0, recv.Length, 0);
                                        socket.Shutdown(SocketShutdown.Both);
                                        socket.Close();

                                   }

    2007年3月23日 上午 08:47

所有回覆