我正嘗試在手持設備和PC之間建立通信。CF 3.5 C中的套接字連接#
我有以下的代碼,對客戶:
public void connect(string IPAddress, int port)
{
// Connect to a remote device.
try
{
IPAddress ipAddress = new IPAddress(new byte[] { 192, 168, 1, 10 });
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect(remoteEP, new AsyncCallback(ConnectCallback), client);
if (connectDone.WaitOne()){
//do something..
}
else{
MessageBox.Show("TIMEOUT on WaitOne");
}
}
catch(Exception e){
MessageBox.Show(e.Message);
}
}
我的問題是,當我在他們溝通罰款的PC上運行他們兩個,但在SmartDevice項目相同的代碼沒有按」 t連接在PC上運行的服務器,它給我這個錯誤:
System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or stablished connection failed
because connected host has failed to respond
我在想什麼?
注:IP地址是硬編碼的碼
編輯內:這裏是我拿from a MSDN example另一個代碼。這也行不通,它說它不可能讀取。在這種情況下,服務器的代碼是一樣的例子,客戶端代碼有修改:
private void button1_Click(object sender, EventArgs e)
{
// In this code example, use a hard-coded
// IP address and message.
string serverIP = "192.168.1.10";//HERE IS THE DIFERENCE
string message = "Hello";
Connect(serverIP, message);
}
在此先感謝您的幫助!
我不使用[ip地址](http://msdn.microsoft.com/en-us/library/t4k07yby.aspx)構造看到很多人,所以我懷疑那。你有沒有嘗試過靜態方法'IPAddress ipAddress = IPAddress.Parse(「192.168.1.10」);'? – jp2code 2012-07-25 17:27:42
@ jp2code我不能在我的CF中使用'Parse'。任何其他想法?謝謝 – 2012-07-25 17:45:05
Ew。你在什麼版本的CF上? – jp2code 2012-07-25 18:00:24