TcpClient for Windows Mobile 6
-
Hello all experts, I am currenting doing my final year project about Windows mobile devices. I have the following code: if (((Button)sender).Text == "Start") { try { //---connect to the server--- client = new TcpClient(); client.Connect(server_IP, PORTNO); data = new byte[client.ReceiveBufferSize]; //---send message--- SendMessage("Send"); //---begin reading data asynchronously from the server--- t = new System.Threading.Thread(ReceiveImageLoop); t.Start(); MessageBox.Show("threat created"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("error !"); } } If I compile this code using Windows XP SP2, it is working fine. However, as I paste the code onto WM6, I got the following error message : " A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll " I see that my windows mobile device could not initiate a TCP connection. Could anyone give me some hints ? Wholeheartly thanks !
-
Hello all experts, I am currenting doing my final year project about Windows mobile devices. I have the following code: if (((Button)sender).Text == "Start") { try { //---connect to the server--- client = new TcpClient(); client.Connect(server_IP, PORTNO); data = new byte[client.ReceiveBufferSize]; //---send message--- SendMessage("Send"); //---begin reading data asynchronously from the server--- t = new System.Threading.Thread(ReceiveImageLoop); t.Start(); MessageBox.Show("threat created"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("error !"); } } If I compile this code using Windows XP SP2, it is working fine. However, as I paste the code onto WM6, I got the following error message : " A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll " I see that my windows mobile device could not initiate a TCP connection. Could anyone give me some hints ? Wholeheartly thanks !
-
A first chance exception is a caught exception. Please post the final exception causing that is causing your error.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Hi Leppie, Just wonder what do you mean by final excpetion. Sorry I am a newbie to C#. Please further help by providing me some guidance to get to the final excpetion. Once again, thank you for your help ! --Leslie
-
The one that made your program stop.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Actually my program didn't stop, it just doesn't work. When I press the button to start the TCP connection, it just shows nothing. Should I paste all the code for your reference ?
Then you are probably catching the exception. You should only do that if you can reliably clean up, which in your case is not so. So remove the try/catch blocks and look at the actual exception being thrown, else you will get nowhere.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Then you are probably catching the exception. You should only do that if you can reliably clean up, which in your case is not so. So remove the try/catch blocks and look at the actual exception being thrown, else you will get nowhere.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Hi leppie, Thank you again for your assistance. The following is the exception details I got: System.Net.Sockets.SocketException was unhandled Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found" ErrorCode=10061 NativeErrorCode=10061 StackTrace: at System.Net.Sockets.Socket.ConnectNoCheck() at System.Net.Sockets.Socket.Connect() at System.Net.Sockets.TcpClient.Connect() at System.Net.Sockets.TcpClient.Connect() at FYP.Form1.button1_Click() at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Button.OnClick() at System.Windows.Forms.ButtonBase.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() at FYP.Program.Main()
-
Hi leppie, Thank you again for your assistance. The following is the exception details I got: System.Net.Sockets.SocketException was unhandled Message="An error message cannot be displayed because an optional resource assembly containing it cannot be found" ErrorCode=10061 NativeErrorCode=10061 StackTrace: at System.Net.Sockets.Socket.ConnectNoCheck() at System.Net.Sockets.Socket.Connect() at System.Net.Sockets.TcpClient.Connect() at System.Net.Sockets.TcpClient.Connect() at FYP.Form1.button1_Click() at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Button.OnClick() at System.Windows.Forms.ButtonBase.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() at FYP.Program.Main()
10061 is the error for port not responding or port not allowed. You sure the DNS is setup correctly on the mobile device? Have you tried connecting using the ip of the server instead? Have you verified the mobile device has actual network access?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
10061 is the error for port not responding or port not allowed. You sure the DNS is setup correctly on the mobile device? Have you tried connecting using the ip of the server instead? Have you verified the mobile device has actual network access?
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)Hi Leppie, The IP address I specified for this fuction was 127.0.0.1. I specifed this IP address since I want the simulator to connect back to my own computer PC (which it contains a program that relays webcam images back to the simulator). I checked the connection for the simulator it seems it is not on the internet. How could I resolve the problem ? Second, sinec this program will be running on a HSDPA phone, will specifying Tcpclient is not enough ? I Googled some code and it requires some other C# class to enable the GPRS function : http://blogs.msdn.com/anthonywong/archive/2006/03/13/550686.aspx[^] Thanks for your help leppie.
-
Hi Leppie, The IP address I specified for this fuction was 127.0.0.1. I specifed this IP address since I want the simulator to connect back to my own computer PC (which it contains a program that relays webcam images back to the simulator). I checked the connection for the simulator it seems it is not on the internet. How could I resolve the problem ? Second, sinec this program will be running on a HSDPA phone, will specifying Tcpclient is not enough ? I Googled some code and it requires some other C# class to enable the GPRS function : http://blogs.msdn.com/anthonywong/archive/2006/03/13/550686.aspx[^] Thanks for your help leppie.
leslie wu wrote:
The IP address I specified for this fuction was 127.0.0.1.
That will connect straight back to the device. You need to specify the network address of your PC (eg 192.168.0.3).
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)