Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TcpClient for Windows Mobile 6

TcpClient for Windows Mobile 6

Scheduled Pinned Locked Moved C#
csharpsysadminhelpquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leslie wu
    wrote on last edited by
    #1

    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 !

    L 1 Reply Last reply
    0
    • L leslie wu

      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 !

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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)

      L 1 Reply Last reply
      0
      • L leppie

        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)

        L Offline
        L Offline
        leslie wu
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • L leslie wu

          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

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          The one that made your program stop.

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          L 1 Reply Last reply
          0
          • L leppie

            The one that made your program stop.

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            L Offline
            L Offline
            leslie wu
            wrote on last edited by
            #5

            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 ?

            L 1 Reply Last reply
            0
            • L leslie wu

              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 ?

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              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)

              L 1 Reply Last reply
              0
              • L leppie

                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)

                L Offline
                L Offline
                leslie wu
                wrote on last edited by
                #7

                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()

                L 1 Reply Last reply
                0
                • L leslie wu

                  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()

                  L Offline
                  L Offline
                  leppie
                  wrote on last edited by
                  #8

                  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)

                  L 1 Reply Last reply
                  0
                  • L leppie

                    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)

                    L Offline
                    L Offline
                    leslie wu
                    wrote on last edited by
                    #9

                    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.

                    L 1 Reply Last reply
                    0
                    • L leslie wu

                      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.

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #10

                      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)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups