By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Sync. socket client and server example

P: n/a
Ole
Hi,

I'm going to develop a socket communication between an instrument (running
CE 5.0 with Compact Fraework V2) and a PC. As the instrument should only
connect to one PC at a time I believe that the sync version of the socket
should be the easiest - or what??? (please tell if I'm wrong).

Are there anyone who is able to point to a Server and Client example code in
C# VS2005 (I've only been able to find a C++ version) ???

Thanks
Ole
May 10 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
See: http://msdn2.microsoft.com/en-us/lib...ts.socket.aspx

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Ole" <ol*@blabla.com> wrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm going to develop a socket communication between an instrument (running
CE 5.0 with Compact Fraework V2) and a PC. As the instrument should only
connect to one PC at a time I believe that the sync version of the socket
should be the easiest - or what??? (please tell if I'm wrong).

Are there anyone who is able to point to a Server and Client example code
in C# VS2005 (I've only been able to find a C++ version) ???

Thanks
Ole

May 10 '06 #2

P: n/a
The main reason to use or not to use a sync socket is how your program is
coded and what else might need to happen on the user interface thread (the
thread that controls the display of forms, etc.) If your data transfer code
is executing is a *different* thread from this UI stuff, I'd use a sync
socket. If not, you'll probably *have* to use an async socket to allow user
interface processing and keep the user interface responsive.

Paul T.

"Ole" <ol*@blabla.com> wrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm going to develop a socket communication between an instrument (running
CE 5.0 with Compact Fraework V2) and a PC. As the instrument should only
connect to one PC at a time I believe that the sync version of the socket
should be the easiest - or what??? (please tell if I'm wrong).

Are there anyone who is able to point to a Server and Client example code
in C# VS2005 (I've only been able to find a C++ version) ???

Thanks
Ole

May 10 '06 #3

P: n/a
Ole
Hi again,

I'm still a bit confused about when to use sync or async socket
communication so I will descibe my needs instead - hoping someone will
comment:
I have a socket server on a CE device communicating with a socket client on
a PC. The server must be able to receive and handle data from the client PC
while transferring other data to the same client - sort of full duplex.

How should I organize my program (sync or async)??

Thanks
Ole
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
The main reason to use or not to use a sync socket is how your program is
coded and what else might need to happen on the user interface thread (the
thread that controls the display of forms, etc.) If your data transfer
code is executing is a *different* thread from this UI stuff, I'd use a
sync socket. If not, you'll probably *have* to use an async socket to
allow user interface processing and keep the user interface responsive.

Paul T.

"Ole" <ol*@blabla.com> wrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm going to develop a socket communication between an instrument
(running CE 5.0 with Compact Fraework V2) and a PC. As the instrument
should only connect to one PC at a time I believe that the sync version
of the socket should be the easiest - or what??? (please tell if I'm
wrong).

Are there anyone who is able to point to a Server and Client example code
in C# VS2005 (I've only been able to find a C++ version) ???

Thanks
Ole


May 17 '06 #4

P: n/a
A Socket is simply an interface to another Socket, on the same machine or
another machine in a network. There is nothing particularly special about
Sockets that makes the rules regarding using them synchronously or
asynchronously in an app any different than any other programming component.
A Socket sends and receives data. So, a synchronous Socket will send and
receive data and block while sending or receiving. An asynchronous Socket
will not block. So, if you think of the sending and receiving as if it were
a method of a class, when would you use a separate thread to call a method
of a class? That's right: when the method blocks execution for a long time,
and the app would work better if the method ran asynchronously. For example,
an email client will send and receive emails asynchronously, so that the
user can perform other tasks with it while it is doing so.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Ole" <ol*@blabla.com> wrote in message
news:u3**************@TK2MSFTNGP03.phx.gbl...
Hi again,

I'm still a bit confused about when to use sync or async socket
communication so I will descibe my needs instead - hoping someone will
comment:
I have a socket server on a CE device communicating with a socket client
on a PC. The server must be able to receive and handle data from the
client PC while transferring other data to the same client - sort of full
duplex.

How should I organize my program (sync or async)??

Thanks
Ole
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
The main reason to use or not to use a sync socket is how your program is
coded and what else might need to happen on the user interface thread
(the thread that controls the display of forms, etc.) If your data
transfer code is executing is a *different* thread from this UI stuff,
I'd use a sync socket. If not, you'll probably *have* to use an async
socket to allow user interface processing and keep the user interface
responsive.

Paul T.

"Ole" <ol*@blabla.com> wrote in message
news:OM**************@TK2MSFTNGP03.phx.gbl...
Hi,

I'm going to develop a socket communication between an instrument
(running CE 5.0 with Compact Fraework V2) and a PC. As the instrument
should only connect to one PC at a time I believe that the sync version
of the socket should be the easiest - or what??? (please tell if I'm
wrong).

Are there anyone who is able to point to a Server and Client example
code in C# VS2005 (I've only been able to find a C++ version) ???

Thanks
Ole



May 17 '06 #5

P: n/a
I would just use sync on another thread as it is much easier to get right.

--
William Stacey [MVP]

"Ole" <ol*@blabla.com> wrote in message
news:u3**************@TK2MSFTNGP03.phx.gbl...
| Hi again,
|
| I'm still a bit confused about when to use sync or async socket
| communication so I will descibe my needs instead - hoping someone will
| comment:
| I have a socket server on a CE device communicating with a socket client
on
| a PC. The server must be able to receive and handle data from the client
PC
| while transferring other data to the same client - sort of full duplex.
|
| How should I organize my program (sync or async)??
|
| Thanks
| Ole
|
|
| "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
| com> wrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
| > The main reason to use or not to use a sync socket is how your program
is
| > coded and what else might need to happen on the user interface thread
(the
| > thread that controls the display of forms, etc.) If your data transfer
| > code is executing is a *different* thread from this UI stuff, I'd use a
| > sync socket. If not, you'll probably *have* to use an async socket to
| > allow user interface processing and keep the user interface responsive.
| >
| > Paul T.
| >
| > "Ole" <ol*@blabla.com> wrote in message
| > news:OM**************@TK2MSFTNGP03.phx.gbl...
| >> Hi,
| >>
| >> I'm going to develop a socket communication between an instrument
| >> (running CE 5.0 with Compact Fraework V2) and a PC. As the instrument
| >> should only connect to one PC at a time I believe that the sync version
| >> of the socket should be the easiest - or what??? (please tell if I'm
| >> wrong).
| >>
| >> Are there anyone who is able to point to a Server and Client example
code
| >> in C# VS2005 (I've only been able to find a C++ version) ???
| >>
| >> Thanks
| >> Ole
| >>
| >
| >
|
|
May 17 '06 #6

P: n/a
Ole
Thanks,

Is it "threadsafe" to use socket.send in one thread and socket receive in
another?

Regards,
Ole

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I would just use sync on another thread as it is much easier to get right.

--
William Stacey [MVP]

"Ole" <ol*@blabla.com> wrote in message
news:u3**************@TK2MSFTNGP03.phx.gbl...
| Hi again,
|
| I'm still a bit confused about when to use sync or async socket
| communication so I will descibe my needs instead - hoping someone will
| comment:
| I have a socket server on a CE device communicating with a socket client
on
| a PC. The server must be able to receive and handle data from the client
PC
| while transferring other data to the same client - sort of full duplex.
|
| How should I organize my program (sync or async)??
|
| Thanks
| Ole
|
|
| "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT
| com> wrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
| > The main reason to use or not to use a sync socket is how your program
is
| > coded and what else might need to happen on the user interface thread
(the
| > thread that controls the display of forms, etc.) If your data
transfer
| > code is executing is a *different* thread from this UI stuff, I'd use
a
| > sync socket. If not, you'll probably *have* to use an async socket to
| > allow user interface processing and keep the user interface
responsive.
| >
| > Paul T.
| >
| > "Ole" <ol*@blabla.com> wrote in message
| > news:OM**************@TK2MSFTNGP03.phx.gbl...
| >> Hi,
| >>
| >> I'm going to develop a socket communication between an instrument
| >> (running CE 5.0 with Compact Fraework V2) and a PC. As the instrument
| >> should only connect to one PC at a time I believe that the sync
version
| >> of the socket should be the easiest - or what??? (please tell if I'm
| >> wrong).
| >>
| >> Are there anyone who is able to point to a Server and Client example
code
| >> in C# VS2005 (I've only been able to find a C++ version) ???
| >>
| >> Thanks
| >> Ole
| >>
| >
| >
|
|

May 17 '06 #7

P: n/a
Yes. It should be obvious, though, that there is no guarantee of ordering
of sends and receives. You can't assume, for example, that no data will be
received until your send is complete, or that either a send or a receive is
atomic and will not return until all data that you think belongs together is
received or sent.

Paul T.

"Ole" <ol*@blabla.com> wrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
Thanks,

Is it "threadsafe" to use socket.send in one thread and socket receive in
another?

Regards,
Ole

"William Stacey [MVP]" <wi************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
I would just use sync on another thread as it is much easier to get right.

--
William Stacey [MVP]

"Ole" <ol*@blabla.com> wrote in message
news:u3**************@TK2MSFTNGP03.phx.gbl...
| Hi again,
|
| I'm still a bit confused about when to use sync or async socket
| communication so I will descibe my needs instead - hoping someone will
| comment:
| I have a socket server on a CE device communicating with a socket
client
on
| a PC. The server must be able to receive and handle data from the
client
PC
| while transferring other data to the same client - sort of full duplex.
|
| How should I organize my program (sync or async)??
|
| Thanks
| Ole
|
|
| "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
DOT
| com> wrote in message news:u4**************@TK2MSFTNGP03.phx.gbl...
| > The main reason to use or not to use a sync socket is how your
program
is
| > coded and what else might need to happen on the user interface thread
(the
| > thread that controls the display of forms, etc.) If your data
transfer
| > code is executing is a *different* thread from this UI stuff, I'd use
a
| > sync socket. If not, you'll probably *have* to use an async socket
to
| > allow user interface processing and keep the user interface
responsive.
| >
| > Paul T.
| >
| > "Ole" <ol*@blabla.com> wrote in message
| > news:OM**************@TK2MSFTNGP03.phx.gbl...
| >> Hi,
| >>
| >> I'm going to develop a socket communication between an instrument
| >> (running CE 5.0 with Compact Fraework V2) and a PC. As the
instrument
| >> should only connect to one PC at a time I believe that the sync
version
| >> of the socket should be the easiest - or what??? (please tell if I'm
| >> wrong).
| >>
| >> Are there anyone who is able to point to a Server and Client example
code
| >> in C# VS2005 (I've only been able to find a C++ version) ???
| >>
| >> Thanks
| >> Ole
| >>
| >
| >
|
|


May 17 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.