Click here to Skip to main content
16,006,065 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Synchronous/Ascynchronous sockets Pin
Zac Howland22-Jun-06 5:29
Zac Howland22-Jun-06 5:29 
GeneralRe: Synchronous/Ascynchronous sockets Pin
led mike22-Jun-06 5:36
led mike22-Jun-06 5:36 
GeneralRe: Synchronous/Ascynchronous sockets Pin
Zac Howland22-Jun-06 6:13
Zac Howland22-Jun-06 6:13 
GeneralRe: Synchronous/Ascynchronous sockets Pin
led mike22-Jun-06 7:22
led mike22-Jun-06 7:22 
GeneralRe: Synchronous/Ascynchronous sockets Pin
Zac Howland22-Jun-06 7:24
Zac Howland22-Jun-06 7:24 
GeneralRe: Synchronous/Ascynchronous sockets Pin
CMas0722-Jun-06 5:58
CMas0722-Jun-06 5:58 
GeneralRe: Synchronous/Ascynchronous sockets Pin
Zac Howland22-Jun-06 6:18
Zac Howland22-Jun-06 6:18 
QuestionRe: Synchronous/Ascynchronous sockets Pin
CMas075-Jul-06 3:34
CMas075-Jul-06 3:34 
So I've been struggling with this for a while, and I have been able to get the server to accept connections from the clients, and send each a message that simply says that it is now connected to the server. As well, the client can receive the message and print it, then wait for user input to send back to the server. This seems to be fine on the client side, because I can call GetLastError after the send and it returns a 0. However, when I call receive after that I get a 10053 error, which is a lost connection, and I can't figure out why. The client, being synchronous, should hang on the receive until it gets sent something, but doesn't because of the 10053 error. Granted that I have nothing happening on the server side with the message sent from the client, but I don't see why that would matter.

Here is my client code that deals with the communication with the server:
<br />
//receives the connection confirmation<br />
recvd = Client->Receive(recBuff, 512, 0);<br />
		<br />
//prints said confirmation	<br />
for(int i = 0; i < recvd; i++)<br />
	cout << recBuff[i];						<br />
cout << endl;<br />
<br />
while(true) {<br />
	//gets user input<br />
	cout << "Next Message:  ";<br />
	string message = "";<br />
	cin >> message;							<br />
	cout << message << endl;<br />
			<br />
	if(message == "quit") {<br />
		Client->Send(message.c_str(), message.length(), 0);<br />
		break;<br />
	}<br />
	else<br />
	{<br />
		//Sends the message to the server<br />
		Client->Send(message.c_str(), message.length(), 0);	<br />
				<br />
		//Breaks here...can't figure out why, <br />
		//but should receive a confirmation <br />
		//that the message was received<br />
		recvd= Client->Receive(recBuff, 512, 0);<br />
				<br />
		//Again, prints the confirmation from the server			for(int i = 0; i < recvd; i++)<br />
			cout << recBuff[i];						cout << endl;<br />
	}<br />
}<br />


I might as well include the server code in case the problem lies in there:
<br />
//...code with WSAStartup and the creation of the listening socket,<br />
//through the Listen() call<br />
<br />
//Begins the thread that will receive the messages from the connected<br />
//clients while this one accepts connections.<br />
AfxBeginThread(ReceiveThread, 0);<br />
<br />
sockaddr_in from;<br />
int fromlen=sizeof(from);<br />
	<br />
//Continuously looks for connections to accept.<br />
while(true)<br />
{<br />
	Sleep(1);<br />
<br />
	//Skeleton class the inherits from CAsyncSocket<br />
	AsyncClient AcceptSocket;<br />
	if(ListenSocket->Accept(AcceptSocket, (struct sockaddr*)&from, &fromlen))<br />
	{<br />
		//Adds the newly connected socket to the vector of <br />
		//connected clients<br />
		clients.push_back(&AcceptSocket);<br />
		char buff[512];<br />
		strcpy(buff, "#Server Ready!");<br />
<br />
		//Sends the connection confirmation message to the <br />
		//newly connected client.<br />
		AcceptSocket.Send(buff, strlen(buff), 0);<br />
<br />
		//Simple message confirmation ont he server-side that <br />
		//a connection was accepted.<br />
		cout << "Accepted a connection from ";<br />
		cout << inet_ntoa(from.sin_addr) << endl;<br />
	}<br />
}<br />


If anyone has any ideas of what the problem is, I would greatly appreciate some input. Thanks! Big Grin | :-D


Richard Alley
Student/Software Engineer
AnswerRe: Synchronous/Ascynchronous sockets Pin
Zac Howland5-Jul-06 4:44
Zac Howland5-Jul-06 4:44 
GeneralRe: Synchronous/Ascynchronous sockets Pin
CMas075-Jul-06 5:02
CMas075-Jul-06 5:02 
GeneralRe: Synchronous/Ascynchronous sockets Pin
Zac Howland5-Jul-06 5:13
Zac Howland5-Jul-06 5:13 
AnswerRe: Synchronous/Ascynchronous sockets Pin
led mike22-Jun-06 5:34
led mike22-Jun-06 5:34 
GeneralRe: Synchronous/Ascynchronous sockets Pin
CMas0722-Jun-06 6:02
CMas0722-Jun-06 6:02 
Questionhow to open a *.txt file Pin
divisameer22-Jun-06 3:58
divisameer22-Jun-06 3:58 
AnswerRe: how to open a *.txt file Pin
toxcct22-Jun-06 3:59
toxcct22-Jun-06 3:59 
QuestionRe: how to open a *.txt file Pin
David Crow22-Jun-06 4:06
David Crow22-Jun-06 4:06 
AnswerRe: how to open a *.txt file Pin
Hamid_RT22-Jun-06 20:10
Hamid_RT22-Jun-06 20:10 
Questionvalues reading from a text document Pin
divisameer22-Jun-06 3:46
divisameer22-Jun-06 3:46 
AnswerRe: values reading from a text document Pin
_AnsHUMAN_ 22-Jun-06 3:50
_AnsHUMAN_ 22-Jun-06 3:50 
GeneralRe: values reading from a text document Pin
Cedric Moonen22-Jun-06 3:54
Cedric Moonen22-Jun-06 3:54 
GeneralRe: values reading from a text document Pin
toxcct22-Jun-06 3:58
toxcct22-Jun-06 3:58 
GeneralRe: values reading from a text document Pin
_AnsHUMAN_ 22-Jun-06 4:02
_AnsHUMAN_ 22-Jun-06 4:02 
AnswerRe: values reading from a text document Pin
Stephen Hewitt22-Jun-06 4:00
Stephen Hewitt22-Jun-06 4:00 
AnswerRe: values reading from a text document Pin
David Crow22-Jun-06 4:01
David Crow22-Jun-06 4:01 
AnswerRe: values reading from a text document Pin
Zac Howland22-Jun-06 4:11
Zac Howland22-Jun-06 4:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.