473,769 Members | 6,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9706
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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ********@TK2MSF TNGP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP02.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******** ********@TK2MSF TNGP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP03.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
4232
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 the existing C++ programs. For example, if I use my existing C++ client app to call the vb.net syncronous socket server example, the server example will never accept the connection(I get an error in the client app). But, I can telnet to the msdn...
7
2388
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 what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
9
3603
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 that its buffer is bigger than this. I did this expecting the data to be read in one pass.
2
15334
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 now see the socket.RecieveTimeout 'property' in the visual studio 2005 help documentation (framework 2.0) and it has example of it being used with TCP socket. This propery is also listed as 'new in .net 2.0'. 1) is the socket.RecieveTimeout...
5
4770
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 set of sensor data per second to a socket server. The socket server will do two things: 1. write data into a file via bsddb; 2. forward the data to a GUI written in wxpython. I am thinking the code should work as follow (not sure it is feasible)...
4
3605
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 client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
8
4682
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 page_load event, I am using atl com component. Here one for loop is there. In this for loop, number of iterations are 1000, I can receive some data using com component. It is just set of some characters like
29
3324
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 use it in sync mode. Any ideas what can I do? Thanks, Zalek.
1
7185
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 site, which is actually for sending strings. I tried to adapt this code so that the client sends an image instead of a string. However, there is something wrong on the server side (i guess)... The server starts listening, the client starts sending...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10050
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.