TcpClient work on emulator but fail in real PocketPC

C

Canon EOS

Hi,

I am relatively new and recently wrote a application using C#, compact .net
framework on Pocket PC. Everything works accordingly in emulator from Visual
Studio .Net. It can connect to server and perform whatever logic according
to my requests.

The problem only arise when I test run the same application on Mini O2.
After narrowing down the problem, I found it always fail at the second line,
which is the connecting... and was catched...

TcpClient f_Client = new TcpClient();
f_Client.Connect("192.168.1.2", 8000);

I hope someone kind enought to give me some ideas of solutions or
suggestions. I thought emulator supposed to be like the real thing.... what
happen?

Thanks for reading.
 
P

Paul G. Tobey [eMVP]

How is the real device connected to the network? And it failed ***how***?
If it threw an exception, what was the exception information (detailed)?

Paul T.
 
C

Canon EOS

It actually can run the .exe file and show all the GUI.

The only problem is when trying to connect, which it actually never did,
just directly go to catch.

How can I get the exception information?
 
G

Guest

I'm also experincing the same problem. In my case, I had developed an
application where the PDA will sent information to a Host PC. When running
the application on the emulator, was able to see information exchange between
a Win32 application but when i deployed it at my real hardware, the error
code I got was something like this: Error in System.Net.Socket.Sockets, No
Such host or something else as I recall. But when I at two seperate machines,
1 running the emulator while the Host runs the Win32 application via
wireless, the emulator was able to send the and the Host capture the
information. Any help are appreciated. Thank you.
 
C

Canon EOS

I had tried to use direct IP and port number. It still fail, while ok on the
emulator, any idea?

I am testing the codes on Mini O2 with WiFi adapter. I can confirm the WiFi
is working, because the IE and MSN is functioning.

Did I miss anything here?

* Glad to know I am not alone...

Alex Yakhnin said:
Try to use the IP address, instead of a host name.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


James OSW said:
I'm also experincing the same problem. In my case, I had developed an
application where the PDA will sent information to a Host PC. When
running
the application on the emulator, was able to see information exchange
between
a Win32 application but when i deployed it at my real hardware, the error
code I got was something like this: Error in System.Net.Socket.Sockets,
No
Such host or something else as I recall. But when I at two seperate
machines,
1 running the emulator while the Host runs the Win32 application via
wireless, the emulator was able to send the and the Host capture the
information. Any help are appreciated. Thank you.


Canon EOS said:
It actually can run the .exe file and show all the GUI.

The only problem is when trying to connect, which it actually never
did,
just directly go to catch.

How can I get the exception information?

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message How is the real device connected to the network? And it failed
***how***?
If it threw an exception, what was the exception information
(detailed)?

Paul T.

Hi,

I am relatively new and recently wrote a application using C#,
compact
.net
framework on Pocket PC. Everything works accordingly in emulator
from
Visual
Studio .Net. It can connect to server and perform whatever logic
according
to my requests.

The problem only arise when I test run the same application on Mini
O2.
After narrowing down the problem, I found it always fail at the
second
line,
which is the connecting... and was catched...

TcpClient f_Client = new TcpClient();
f_Client.Connect("192.168.1.2", 8000);

I hope someone kind enought to give me some ideas of solutions or
suggestions. I thought emulator supposed to be like the real
thing....
what
happen?

Thanks for reading.
 
G

Guest

I was using the IP but not hostname. I had also actually tried both TCP and
UDP method. I'll include some part of the coding for better understanding of
the situation.

Client Side

'Send Message to specific Ip and Port (first send buffer lenght and then the
buffer holding message)
Public Sub SendMessage(ByVal Ip As String, ByVal Port As Integer, ByVal
Message As String)
Dim tempclient As System.Net.Sockets.TcpClient
Dim Buffer() As Byte =
System.Text.Encoding.Default.GetBytes(Message.ToCharArray)
If Not checkip(Ip) Then Throw New ArgumentException("Ip is not in
the right format")
Try
tempclient = New System.Net.Sockets.TcpClient
tempclient.Connect(Ip, Port)
sendBufferLenght(Buffer.Length, tempclient)
tempclient.GetStream.Write(Buffer, 0, Buffer.Length)
tempclient.Close()
Catch
tempclient.Close()
Throw New Exception("Remote IP is not reachable")
End Try
End Sub

'Check ip string to be an ip address
Private Function checkip(ByVal ip As String) As Boolean
Try
IPAddress.Parse(ip)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class

'Send Information
Try
Client.SendMessage(IP, 6666, Combine)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error sending message")
End Try
==================================================

Server Side

If (Server Is Nothing) Then
'Retrieve(PORT)
Dim PORT As Integer
Server = Nothing
Server = New AppSignalDetection.ServerClass(6666, True)
End If

Private Sub OnIncomingMessage(ByVal Args As
AppSignalDetection.ServerClass.InMessEvArgs) Handles Server.IncomingMessage
'Get Information
msgbox(args.message)
End Sub
==================================================

Communication between emulator and another seperate PC or locally are
working but not with the real device. I was wondering does the application
required additional libraries or external components for real hardware?

Thanks.
 
P

Paul G. Tobey [eMVP]

Try using regular sockets, not TcpClients and bind to the IP address of the
WiFi adapter. It's possible that a bug (or, at least, I'd call it bug),
could try to send your traffic over a connection which doesn't current exist
(ActiveSync, cellular, etc.)

In case this is a bug, we also need the detailed version information for the
device: OS version/WM version, any other version information supplied by the
Control Panel, etc.

Paul T.
 
A

Alex Feinman [MVP]

There is an important distinction that you probably missed:

When you type New TcpClient("192.168.1.1"), the string is still passed to
Dns.GetHostByName. Your device most likely suffers from inability to talk to
the internal DNS server and hence has no idea what is "192.168.1.1"
You need to change code to use New TcpClient(new
IPEndPoint(IPAddress.Parse("192.168.1.1"), 80))

--
Alex Feinman
---
Visit http://www.opennetcf.org
Canon EOS said:
I had tried to use direct IP and port number. It still fail, while ok on
the emulator, any idea?

I am testing the codes on Mini O2 with WiFi adapter. I can confirm the
WiFi is working, because the IE and MSN is functioning.

Did I miss anything here?

* Glad to know I am not alone...

Alex Yakhnin said:
Try to use the IP address, instead of a host name.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


James OSW said:
I'm also experincing the same problem. In my case, I had developed an
application where the PDA will sent information to a Host PC. When
running
the application on the emulator, was able to see information exchange
between
a Win32 application but when i deployed it at my real hardware, the
error
code I got was something like this: Error in System.Net.Socket.Sockets,
No
Such host or something else as I recall. But when I at two seperate
machines,
1 running the emulator while the Host runs the Win32 application via
wireless, the emulator was able to send the and the Host capture the
information. Any help are appreciated. Thank you.


:

It actually can run the .exe file and show all the GUI.

The only problem is when trying to connect, which it actually never
did,
just directly go to catch.

How can I get the exception information?

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message How is the real device connected to the network? And it failed
***how***?
If it threw an exception, what was the exception information
(detailed)?

Paul T.

Hi,

I am relatively new and recently wrote a application using C#,
compact
.net
framework on Pocket PC. Everything works accordingly in emulator
from
Visual
Studio .Net. It can connect to server and perform whatever logic
according
to my requests.

The problem only arise when I test run the same application on Mini
O2.
After narrowing down the problem, I found it always fail at the
second
line,
which is the connecting... and was catched...

TcpClient f_Client = new TcpClient();
f_Client.Connect("192.168.1.2", 8000);

I hope someone kind enought to give me some ideas of solutions or
suggestions. I thought emulator supposed to be like the real
thing....
what
happen?

Thanks for reading.
 
G

Guest

Basically I had tried a few models of pocket PCs' and I still experince the
same problem. I'm currently trying to recode my whole application by using
socket.
 
P

Paul G. Tobey [eMVP]

Maybe just recoding the connection in a test program would be a better use
of your time. Maybe you want to use TcpClient in the real program. We're
just trying to figure out what's wrong, at this point.

Paul T.
 
G

Guest

Socket programming was working as suggested as I tried a sample code from the
sample code section - Signature Caputure which was using socket instate of
TcpListen and TcpClient. Basically my coding doesn't show any error by the
complier. Just that when I deployed it to the hardware, the application
doesn't seem to work; but it's working 100% perfectly using the emulator.


Paul G. Tobey said:
Maybe just recoding the connection in a test program would be a better use
of your time. Maybe you want to use TcpClient in the real program. We're
just trying to figure out what's wrong, at this point.

Paul T.

James OSW said:
Basically I had tried a few models of pocket PCs' and I still experince
the
same problem. I'm currently trying to recode my whole application by using
socket.


Alex Yakhnin said:
Also, you can install the excellent tools "vxUtil - is a suite of
network/internet utilities" and try ping the ip address.

http://www.cam.com/vxutil_pers.html

-Alex

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
wrote in message Try using regular sockets, not TcpClients and bind to the IP address of
the WiFi adapter. It's possible that a bug (or, at least, I'd call it
bug), could try to send your traffic over a connection which doesn't
current exist (ActiveSync, cellular, etc.)

In case this is a bug, we also need the detailed version information
for
the device: OS version/WM version, any other version information
supplied
by the Control Panel, etc.

Paul T.

I was using the IP but not hostname. I had also actually tried both TCP
and
UDP method. I'll include some part of the coding for better
understanding
of
the situation.

Client Side

'Send Message to specific Ip and Port (first send buffer lenght and
then
the
buffer holding message)
Public Sub SendMessage(ByVal Ip As String, ByVal Port As Integer,
ByVal
Message As String)
Dim tempclient As System.Net.Sockets.TcpClient
Dim Buffer() As Byte =
System.Text.Encoding.Default.GetBytes(Message.ToCharArray)
If Not checkip(Ip) Then Throw New ArgumentException("Ip is not
in
the right format")
Try
tempclient = New System.Net.Sockets.TcpClient
tempclient.Connect(Ip, Port)
sendBufferLenght(Buffer.Length, tempclient)
tempclient.GetStream.Write(Buffer, 0, Buffer.Length)
tempclient.Close()
Catch
tempclient.Close()
Throw New Exception("Remote IP is not reachable")
End Try
End Sub

'Check ip string to be an ip address
Private Function checkip(ByVal ip As String) As Boolean
Try
IPAddress.Parse(ip)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class

'Send Information
Try
Client.SendMessage(IP, 6666, Combine)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error sending message")
End Try
==================================================

Server Side

If (Server Is Nothing) Then
'Retrieve(PORT)
Dim PORT As Integer
Server = Nothing
Server = New AppSignalDetection.ServerClass(6666, True)
End If

Private Sub OnIncomingMessage(ByVal Args As
AppSignalDetection.ServerClass.InMessEvArgs) Handles
Server.IncomingMessage
'Get Information
msgbox(args.message)
End Sub
==================================================

Communication between emulator and another seperate PC or locally are
working but not with the real device. I was wondering does the
application
required additional libraries or external components for real
hardware?

Thanks.
 
P

Paul G. Tobey [eMVP]

So, if I understand you, you have a sample now which exhibits the problem
and is based on Socket not on TcpClient. Have you tried my suggestion for
binding to the IP of the WiFi adapter?

Paul T.

James OSW said:
Socket programming was working as suggested as I tried a sample code from
the
sample code section - Signature Caputure which was using socket instate of
TcpListen and TcpClient. Basically my coding doesn't show any error by the
complier. Just that when I deployed it to the hardware, the application
doesn't seem to work; but it's working 100% perfectly using the emulator.


Paul G. Tobey said:
Maybe just recoding the connection in a test program would be a better
use
of your time. Maybe you want to use TcpClient in the real program.
We're
just trying to figure out what's wrong, at this point.

Paul T.

James OSW said:
Basically I had tried a few models of pocket PCs' and I still experince
the
same problem. I'm currently trying to recode my whole application by
using
socket.


:

Also, you can install the excellent tools "vxUtil - is a suite of
network/internet utilities" and try ping the ip address.

http://www.cam.com/vxutil_pers.html

-Alex

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com
www.opennetcf.org

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message Try using regular sockets, not TcpClients and bind to the IP address
of
the WiFi adapter. It's possible that a bug (or, at least, I'd call
it
bug), could try to send your traffic over a connection which doesn't
current exist (ActiveSync, cellular, etc.)

In case this is a bug, we also need the detailed version information
for
the device: OS version/WM version, any other version information
supplied
by the Control Panel, etc.

Paul T.

I was using the IP but not hostname. I had also actually tried both
TCP
and
UDP method. I'll include some part of the coding for better
understanding
of
the situation.

Client Side

'Send Message to specific Ip and Port (first send buffer lenght and
then
the
buffer holding message)
Public Sub SendMessage(ByVal Ip As String, ByVal Port As
Integer,
ByVal
Message As String)
Dim tempclient As System.Net.Sockets.TcpClient
Dim Buffer() As Byte =
System.Text.Encoding.Default.GetBytes(Message.ToCharArray)
If Not checkip(Ip) Then Throw New ArgumentException("Ip is
not
in
the right format")
Try
tempclient = New System.Net.Sockets.TcpClient
tempclient.Connect(Ip, Port)
sendBufferLenght(Buffer.Length, tempclient)
tempclient.GetStream.Write(Buffer, 0, Buffer.Length)
tempclient.Close()
Catch
tempclient.Close()
Throw New Exception("Remote IP is not reachable")
End Try
End Sub

'Check ip string to be an ip address
Private Function checkip(ByVal ip As String) As Boolean
Try
IPAddress.Parse(ip)
Return True
Catch ex As Exception
Return False
End Try
End Function
End Class

'Send Information
Try
Client.SendMessage(IP, 6666, Combine)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error sending message")
End Try
==================================================

Server Side

If (Server Is Nothing) Then
'Retrieve(PORT)
Dim PORT As Integer
Server = Nothing
Server = New AppSignalDetection.ServerClass(6666, True)
End If

Private Sub OnIncomingMessage(ByVal Args As
AppSignalDetection.ServerClass.InMessEvArgs) Handles
Server.IncomingMessage
'Get Information
msgbox(args.message)
End Sub
==================================================

Communication between emulator and another seperate PC or locally
are
working but not with the real device. I was wondering does the
application
required additional libraries or external components for real
hardware?

Thanks.
 
G

Guest

No I have not because I'm not sure how to do it. Could you please state and
example for me? Thanks.
 
C

Canon EOS

Thank you so much.

I had solved the issue. It is indeed the DNS issue...

Alex Feinman said:
There is an important distinction that you probably missed:

When you type New TcpClient("192.168.1.1"), the string is still passed to
Dns.GetHostByName. Your device most likely suffers from inability to talk
to the internal DNS server and hence has no idea what is "192.168.1.1"
You need to change code to use New TcpClient(new
IPEndPoint(IPAddress.Parse("192.168.1.1"), 80))

--
Alex Feinman
---
Visit http://www.opennetcf.org
Canon EOS said:
I had tried to use direct IP and port number. It still fail, while ok on
the emulator, any idea?

I am testing the codes on Mini O2 with WiFi adapter. I can confirm the
WiFi is working, because the IE and MSN is functioning.

Did I miss anything here?

* Glad to know I am not alone...

Alex Yakhnin said:
Try to use the IP address, instead of a host name.

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


:

I'm also experincing the same problem. In my case, I had developed an
application where the PDA will sent information to a Host PC. When
running
the application on the emulator, was able to see information exchange
between
a Win32 application but when i deployed it at my real hardware, the
error
code I got was something like this: Error in System.Net.Socket.Sockets,
No
Such host or something else as I recall. But when I at two seperate
machines,
1 running the emulator while the Host runs the Win32 application via
wireless, the emulator was able to send the and the Host capture the
information. Any help are appreciated. Thank you.


:

It actually can run the .exe file and show all the GUI.

The only problem is when trying to connect, which it actually never
did,
just directly go to catch.

How can I get the exception information?

"Paul G. Tobey [eMVP]" <ptobey no spam AT no instrument no spam DOT
com>
wrote in message How is the real device connected to the network? And it failed
***how***?
If it threw an exception, what was the exception information
(detailed)?

Paul T.

Hi,

I am relatively new and recently wrote a application using C#,
compact
.net
framework on Pocket PC. Everything works accordingly in emulator
from
Visual
Studio .Net. It can connect to server and perform whatever logic
according
to my requests.

The problem only arise when I test run the same application on
Mini O2.
After narrowing down the problem, I found it always fail at the
second
line,
which is the connecting... and was catched...

TcpClient f_Client = new TcpClient();
f_Client.Connect("192.168.1.2", 8000);

I hope someone kind enought to give me some ideas of solutions or
suggestions. I thought emulator supposed to be like the real
thing....
what
happen?

Thanks for reading.
 
G

Guest

Could someone please provide the information for IP binding?
I'm currently stuck in the middle of nowhere :-\
 
P

Paul G. Tobey [eMVP]

Well, consulting the help, look up the Socket class. Choose the method
entry. Read down the list until you hit Bind(). Read the information about
Bind(). It associates the local end of the socket (the end on your device),
with a given port number and IP address. Well, we don't care about the port
number, but we want to set the IP address to the address currently in use by
the WiFi adapter. You'll have to figure out what that value is by
consulting the Network and DialUp connections applet. Call Bind() something
like this:

socket.Bind( IPAddress.Parse( "172.16.0.1" ), 0 /* any port can be used
*/ );

Paul T.
 
P

Paul G. Tobey [eMVP]

Whoops, shouldn't have technical discussions on other topics in the middle
of writing messages...

socket.Bind( new IPEndPoint( IPAddress.Parse( "172.16.0.1" ), 0 /* any port
*/ ) );

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top