473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Sync. socket client and server example

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
7 9684
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Luke Balding | last post by:
I'm toying with the idea of swaping out some of my C++ client and server socket programs with vb.net equivs. but I finding that the examples included in the msdn do not seem to interoperate with...
7
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
29
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.