473,466 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Client / Server 'Shall I put a sock(et) in it?'

I'm sorry to bother you with this question but it was either this or
giving up and trying to go for a simpler solution (which I will if
this is not gonna work out..)

I'm afraid this is way out of my league but then again why not give it
a shot...

I've used the Pocket PC Signature Application Sample from:
http://msdn.microsoft.com/library/de...gnatureApp.asp

and I wanted to not only being able to send something from the client
to the server but also back from server to client.
So I started with sending a string 'helo' from client to server and
expecting a string back with 'helo2u2'.
If I send the string the server responds and sends back the 'helo2u2'
string with a terminator.
I've copied the code (with the while loop in it) from the server to
the client which resides in the 'ReceiveCallback' function to collect
all data send from the server **[including the terminator? / is the
loop necesary?]**

The Client side code however returns as far as I can see 3 kinds of
strings
- an empty one
- a right one ("message box is being displayed")
- a "helo2u2helo2u2" string

Sometimes the code just 'stops/hangs' at:
bytesRead = _socket.Receive(buf)

I guess there's one percent of sockets I know and 99% I don't know but
if a Socket Guru can point me in the right direction I will be more
then gratefull..

Kind regards,

Mike

//Code:

[Server side]

If System.Text.Encoding.ASCII.GetString(_encryptData) = "helo" Then
Dim StrByte As Byte() = _
System.Text.Encoding.ASCII.GetBytes("helo2u2")
_server.Send(StrByte)
End If

' Send data to the server.
Public Sub Send(ByVal data() As Byte)
Dim _asyncEvent As ManualResetEvent = New
ManualResetEvent(True)
' send the data
_socket.BeginSend(data, 0, data.Length, _
SocketFlags.None, Nothing, Nothing)

' send the terminator
_asyncEvent.Reset()
_socket.BeginSend(Network.TerminatorBytes, 0, _
Network.TerminatorBytes.Length, SocketFlags.None, _
AddressOf SendCallback, True)
End Sub
[Client side]

' Read data from server.
Public Sub Receive()
_asyncEvent.Reset()
_socket.BeginReceive(_readBuffer, 0, _readBuffer.Length, _
SocketFlags.None, AddressOf ReceiveCallback, Nothing)
End Sub

Private Sub ReceiveCallback(ByVal ar As IAsyncResult)
Try
_socket.EndReceive(ar)

' sit in this loop until connection is broken
' handle client commands and send back response
Dim bListen As Boolean = True
While bListen
' reset everything for the next read message
Dim bReadMessage As Boolean = True
Dim bytesRead As Integer = 0
Dim totalBytes As Integer = 0

' hold incoming data
Dim streamRead As New MemoryStream
Dim TempString As String

While bReadMessage
Dim buf(1023) As Byte

' loop that reads incoming message
' buf is temp holder and the MemoryStream
' contains all of the bits

bytesRead = _socket.Receive(buf)
If bytesRead > 0 Then
streamRead.Write(buf, 0, bytesRead)
bReadMessage = Not
Network.CheckForTerminator(streamRead.ToArray())
totalBytes += bytesRead
Else
' client disconnected
Throw New Exception("Client disconnected.")
End If
End While

' done reading incoming message, now process the
command
ProcessCommand(streamRead)
streamRead.Close()
End While

Catch ex As Exception
End Try
End Sub

' Process the command that was received from the client.
Private Sub ProcessCommand(ByVal streamRead As MemoryStream)
Try
' remove message terminator
streamRead.SetLength((streamRead.Length -
Network.Terminator.Length))
' get the command data
streamRead.Position = 0
Dim data As Byte() = streamRead.ToArray()

If System.Text.Encoding.ASCII.GetString(data) = "helo2u2"
Then
MsgBox(System.Text.Encoding.ASCII.GetString(data))
End If

Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Nov 20 '05 #1
1 1486
Hi Mike,

Without Bill Ryan, I expect he sees this and normaly he answer than., There
are not so much who use the pocket PC programming in this newsgroup.

However there is a special newsgroup

microsoft.public.dotnet.framework.compactframework

I advice you to ask it there as well.

Cor
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: jab | last post by:
Je veux lier (join) une table qui se trouve dans une database avec une qui se trouve dans une autre database. Les 2 databases sont sur le même serveur en l'occurence DB2/NT 7.2.9. J'ai créé un...
6
by: DevX | last post by:
Hello, I have a big intranet that I run with IIS 6.0. I need to log the client's machine names, and I found on the web istruction on how to use REMOTE_HOST server variable while enabling...
0
by: tsic | last post by:
Bonjour, Voilà, j'ai débuté recemment avec python et je veux faire une connexion client serveur (windows) par l'intermédiaire d'une interface QT Designer v 4. j'ai choisi ERIC v 4 comme IDE. ...
1
by: tsic | last post by:
Bonjour, je suis bloqué ilya preque 2 semaines dans le code suivant. je veut que le client et le serveur envoyent leurs message d'une maniere comme msn. je crois qu'ilya quelque chose à ajouter dans...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.