C
Cat
This has been really troubling me, at least for few days. I tried to
solve it myself but I finally gave up and am asking for some advice.
What I'm trying to do is rather simple. To communicate between PDA and
PC via good old TCP socket. Since I dont' have a PocketPC, I used the
emulator that came with VS.NET
First, I tried like
Dim client As TcpClient = Nothing
Try
client = New TcpClient()
client.Connect("my ip address", 7778)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show(client.Client.Connected)
The problem was, even though I'd typed a wrong ip, the message box
always showed "True". The connection error only occurred when the
internet connection itself was unavailable.
Second,
Dim mySoc As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
mySoc.BeginConnect(New IPEndPoint(IPAddress.Parse("my ip
address"), 7778),
AddressOf OnConnect, mySoc)
End Sub
Sub OnConnect(ByVal result As IAsyncResult)
Dim mySoc As Socket = CType(result.AsyncState, Socket)
mySoc.EndConnect(result)
System.Diagnostics.Debug.WriteLine(mySoc.Connected)
System.Diagnostics.Debug.WriteLine(mySoc.RemoteEndPoint.ToString())
End Sub
This was the same, it always printed "True" even thouth the IP address
was wrong. I've tested this on VS.NET 2008 (WM 5.0 Emulator + Mobile
Device Center) and VS.NET 2005 (PPC 2003 emulator + ActiveSync), but
the results were the same.
All I want is simple text-based message exchanging. But I'm stuck at
the very basic stage like checking if the message was sent and
received. Is there any sample code that I can refer to? Please give me
some advice. Thank you a lot.
PS ------- The server side code was like
Dim myIP As IPAddress = Nothing
For Each i As IPAddress In
Dns.GetHostAddresses(Dns.GetHostName())
If i.AddressFamily = AddressFamily.InterNetwork Then
myIP = i
Exit For
End If
Next
If myIP Is Nothing Then
MessageBox.Show("Can't get the IP4 address of this
computer.")
End If
MyListener = New TcpListener(myIP, 7778)
MyListener.Start()
MyListener.BeginAcceptTcpClient(AddressOf OnClient, MyListener)
solve it myself but I finally gave up and am asking for some advice.
What I'm trying to do is rather simple. To communicate between PDA and
PC via good old TCP socket. Since I dont' have a PocketPC, I used the
emulator that came with VS.NET
First, I tried like
Dim client As TcpClient = Nothing
Try
client = New TcpClient()
client.Connect("my ip address", 7778)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
MessageBox.Show(client.Client.Connected)
The problem was, even though I'd typed a wrong ip, the message box
always showed "True". The connection error only occurred when the
internet connection itself was unavailable.
Second,
Dim mySoc As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
mySoc.BeginConnect(New IPEndPoint(IPAddress.Parse("my ip
address"), 7778),
AddressOf OnConnect, mySoc)
End Sub
Sub OnConnect(ByVal result As IAsyncResult)
Dim mySoc As Socket = CType(result.AsyncState, Socket)
mySoc.EndConnect(result)
System.Diagnostics.Debug.WriteLine(mySoc.Connected)
System.Diagnostics.Debug.WriteLine(mySoc.RemoteEndPoint.ToString())
End Sub
This was the same, it always printed "True" even thouth the IP address
was wrong. I've tested this on VS.NET 2008 (WM 5.0 Emulator + Mobile
Device Center) and VS.NET 2005 (PPC 2003 emulator + ActiveSync), but
the results were the same.
All I want is simple text-based message exchanging. But I'm stuck at
the very basic stage like checking if the message was sent and
received. Is there any sample code that I can refer to? Please give me
some advice. Thank you a lot.
PS ------- The server side code was like
Dim myIP As IPAddress = Nothing
For Each i As IPAddress In
Dns.GetHostAddresses(Dns.GetHostName())
If i.AddressFamily = AddressFamily.InterNetwork Then
myIP = i
Exit For
End If
Next
If myIP Is Nothing Then
MessageBox.Show("Can't get the IP4 address of this
computer.")
End If
MyListener = New TcpListener(myIP, 7778)
MyListener.Start()
MyListener.BeginAcceptTcpClient(AddressOf OnClient, MyListener)