[問題] socket 連線問題
目前寫出一用戶端程式,在與伺服端的連結中
出現
連線嘗試失敗,因為連線對象有一段時間並未正確回應
或是連線建立失敗,因為連線的主機無法回應。
的反應
complier有過~~
在伺服端的執行已經開啟
卻還是出現此樣的反應
目前是使用C#來做SOCKET無線網路來做傳輸
使用無線AP分享器與無線網卡來作媒介
問題有可能出現在IP還是PORT的地方嗎??
先謝謝
以下是程式碼
amespace ConsoleApplication1
{
class Program
{
public static void StartClient() {
// Data buffer for incoming data.
byte[] bytes = new byte[1024];
// Connect to a remote device.
try {
// Establish the remote endpoint for the socket.
// This example uses port 11000 on the local computer.
//IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = IPAddress.Parse("192.168.182.12");//ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress,5712);
// Create a TCP/IP socket.
Socket sender = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp );
// Connect the socket to the remote endpoint. Catch any errors.
try {
sender.Connect(remoteEP);
Console.WriteLine("Socket connected to {0}",
sender.RemoteEndPoint.ToString());
// Encode the data string into a byte array.
byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");
// Send the data through the socket.
int bytesSent = sender.Send(msg);
// Receive the response from the remote device.
int bytesRec = sender.Receive(bytes);
Console.WriteLine("Echoed test = {0}",
Encoding.ASCII.GetString(bytes,0,bytesRec));
// Release the socket.
sender.Shutdown(SocketShutdown.Both);
sender.Close();
} catch (ArgumentNullException ane) {
Console.WriteLine("ArgumentNullException : {0}",ane.ToString());
} catch (SocketException se) {
Console.WriteLine("SocketException : {0}",se.ToString());
} catch (Exception e) {
Console.WriteLine("Unexpected exception : {0}", e.ToString());
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.71.97.105
※ 編輯: sendo3022 來自: 210.71.97.105 (12/06 14:04)
推
12/06 16:16, , 1F
12/06 16:16, 1F
→
12/06 16:17, , 2F
12/06 16:17, 2F
推
12/07 14:34, , 3F
12/07 14:34, 3F