473,388 Members | 1,524 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,388 software developers and data experts.

Network Sockets Question

jm
I have a client and a server (of course). The listener, from the code
I got on Microsoft (MSDN) uses a While (true) to wait on accepting a
socket. When the message sent to the listener application is
complete, the message is processed and the While loop, since true,
goes back and waits for another socket.

The problem I have is that there are other functions and procedures
that are called within this loop. They are never being activated
because the While(true) is always running. The calls are in the
middle of the while loop:

While (true)
{

if (x==y)
{
call_this_procedure(); //may get called, but never works; have
stepped thorough it seen that it hits this, it just doesn't work; take
out the While(true) and it works;
}
}

but that "call_this_procedure()" never works. If I take out the
While(true) it works.

Someone told me I needed to use async sockets. Again, using MSDN, I
was able to get some code working, but the result was the same.
Again, they had the listener in the While(true) construct. I cannot
get things to work right this way. Can someone please advise. Thank
you for any help.
Nov 16 '05 #1
3 1467
jm, what are you doing in the call_this_procedure()? Have you tried
executing a simple function in there which just prints something out or
other trivial task? Do you get an error?

--
Greg Ewing [MVP]
http://www.citidc.com

"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have a client and a server (of course). The listener, from the code
I got on Microsoft (MSDN) uses a While (true) to wait on accepting a
socket. When the message sent to the listener application is
complete, the message is processed and the While loop, since true,
goes back and waits for another socket.

The problem I have is that there are other functions and procedures
that are called within this loop. They are never being activated
because the While(true) is always running. The calls are in the
middle of the while loop:

While (true)
{

if (x==y)
{
call_this_procedure(); //may get called, but never works; have
stepped thorough it seen that it hits this, it just doesn't work; take
out the While(true) and it works;
}
}

but that "call_this_procedure()" never works. If I take out the
While(true) it works.

Someone told me I needed to use async sockets. Again, using MSDN, I
was able to get some code working, but the result was the same.
Again, they had the listener in the While(true) construct. I cannot
get things to work right this way. Can someone please advise. Thank
you for any help.

Nov 16 '05 #2
Please post some code. Thanks.

--
William Stacey, MVP

"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have a client and a server (of course). The listener, from the code
I got on Microsoft (MSDN) uses a While (true) to wait on accepting a
socket. When the message sent to the listener application is
complete, the message is processed and the While loop, since true,
goes back and waits for another socket.

The problem I have is that there are other functions and procedures
that are called within this loop. They are never being activated
because the While(true) is always running. The calls are in the
middle of the while loop:

While (true)
{

if (x==y)
{
call_this_procedure(); //may get called, but never works; have
stepped thorough it seen that it hits this, it just doesn't work; take
out the While(true) and it works;
}
}

but that "call_this_procedure()" never works. If I take out the
While(true) it works.

Someone told me I needed to use async sockets. Again, using MSDN, I
was able to get some code working, but the result was the same.
Again, they had the listener in the While(true) construct. I cannot
get things to work right this way. Can someone please advise. Thank
you for any help.


Nov 16 '05 #3
Jim,

If you're doing the following:

while(true)
{
Socket client = serverSocket.Accept();

if (x == y)
{
DoSomething();
}
}

Then of course your method won't fire until a socket is actually accepted.
If you have other methods that need to fire continually on the same thread
as the listening socket, you should use the Poll() method, like so:

while(true)
{
if (serverSocket.Poll(1000000, SelectMode.SelectRead))
{
Socket client = serverSocket.Accept();
...do whatever with the client, spawn a worker thread, etc...
}

if (x == y)
{
DoSomething();
}
}

The Poll method will poll the server socket for 1 second (the 1000000 is
microseconds) to see if it can read from it (in this case, a read would mean
that a client has connected). If it can read, the code accepts the client
and continues on its merry way. If it can't read, the poll will timeout and
continue on to the "if (x == y)" part, which will then loop back around
eventually and poll the server socket again.

Alternatively, if you do wish to use asyncronous sockets, you can use
BeginAccept instead and register a delegate that will be called when a
client connects, which will then get executed on a different thread.

-Brian Newtz
"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have a client and a server (of course). The listener, from the code
I got on Microsoft (MSDN) uses a While (true) to wait on accepting a
socket. When the message sent to the listener application is
complete, the message is processed and the While loop, since true,
goes back and waits for another socket.

The problem I have is that there are other functions and procedures
that are called within this loop. They are never being activated
because the While(true) is always running. The calls are in the
middle of the while loop:

While (true)
{

if (x==y)
{
call_this_procedure(); //may get called, but never works; have
stepped thorough it seen that it hits this, it just doesn't work; take
out the While(true) and it works;
}
}

but that "call_this_procedure()" never works. If I take out the
While(true) it works.

Someone told me I needed to use async sockets. Again, using MSDN, I
was able to get some code working, but the result was the same.
Again, they had the listener in the While(true) construct. I cannot
get things to work right this way. Can someone please advise. Thank
you for any help.

Nov 16 '05 #4

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

Similar topics

3
by: Jay | last post by:
Hi, I implemeneted an FTP client and server long time back using Java. I found sockets porgramming in java quite useful and easy to handle. I now wanted to implement a similar program using C++....
6
by: John Walton | last post by:
Hello, everyone. I just began school, and they already assigned us science fair. Since I'm in 8th grade, I get to do demonstrations for our projects. I'm probably going to demonstrate Python's...
2
by: Bruce Vander Werf | last post by:
I am developing a network client application (using the Socket class) that will need to make simultaneous TCP connections to many (100 or more) servers. In this case, which would be a better...
6
by: Eric | last post by:
Does anyone know of any GOOD network programming book(s) that are C# based, as well as any online tutorials and forums on network programming? Thanks
7
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the...
0
by: Eddy_w | last post by:
Hello, I try to ping from my mobile device with a wireless connection to my pc. I found the class clsping on the internet and it works perfect with application from pc to pc but when i use it...
10
by: CCLeasing | last post by:
How do I communicate between different user instances of my windows forms project? Im trying to write a program that will run on a network of 15 pcs. 5 of the pc's will run the admin part of...
6
by: Bernie Hunt | last post by:
I need to learn network communications. The project will have a server and multiple clients that need to receive information from the server. The network will be the company's internal network and...
4
by: Chandra | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
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...

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.