C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old January 30th, 2003, 04:24 PM
florescence florescence is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 2 florescence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sockets, echoclient, error 10061

hi, I am trying to write a simple echoclient program in C (windows) yet when I try to run it with my own computer's IP address as the server, I get error 10061, or, connection has been denied. Would there be any way to fix this? Thanks. And, the code is below.
Jen

#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>


#define RCVBUFSIZE 32
void DieWithError(char *errorMessage);

int main(int argc, char *argv[])
{
int sock;
struct sockaddr_in echoServAddr;
unsigned short echoServPort;
char *servIP;
char *echoString;
char echoBuffer[RCVBUFSIZE];
int echoStringLen;
int bytesRcvd, totalBytesRcvd;
WSADATA wsaData;



if ((argc<3) || (argc>4))
{
fprintf(stdout,"Usage: %s <Server IP> <Echo Word> [<Echo Port>]\n",argv[0]);
exit(1);
}

servIP=argv[1];
echoString=argv[2];

if (argc==4)
echoServPort = atoi(argv[3]);
else
echoServPort = 7;

if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0)
{
fprintf(stderr,"WSAStartup () failed");
exit(1);
}

if ((sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))<0)
DieWithError("socket() failed");

memset(&echoServAddr,0,sizeof(echoServAddr));
echoServAddr.sin_family = AF_INET;
echoServAddr.sin_addr.s_addr = inet_addr(servIP);
echoServAddr.sin_port = htons(echoServPort);


if (connect(sock, (struct sockaddr *)&echoServAddr, sizeof(echoServAddr))<0)
DieWithError("connect() failed");

echoStringLen = strlen(echoString);

if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send() sent a different number of bytes than expected");

totalBytesRcvd = 0;
printf("Received: ");
while (totalBytesRcvd < echoStringLen)
{
if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE -1, 0)) <=0)
DieWithError("recv() failed or connection closed prematurely");
totalBytesRcvd += bytesRcvd;
echoBuffer[bytesRcvd] = '\0';
printf(echoBuffer);
}

printf("\n");
closesocket(sock);
WSACleanup();
exit(0);

}

void DieWithError(char *errorMessage)
{
fprintf(stderr,"%s: %d\n",errorMessage, WSAGetLastError());
exit(1);

}

Reply With Quote
  #2  
Old January 30th, 2003, 04:34 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
do you have an "echo" service running?
where do you connect to? 127.0.0.1 (aka localhost) or your real IP?
for the latter, XP´s built-in firewall is blocking the access?!
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old January 30th, 2003, 07:23 PM
florescence florescence is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 2 florescence User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
sorry, i was kind of confused.
yes, i do have a server running. and i'm using port 1087, but i still get error 10061. the server is running on windows ME and the client is running on windows 2000. I connect to the server's IP.

Reply With Quote
  #4  
Old February 1st, 2003, 11:39 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,799 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 9 h 56 m 11 sec
Reputation Power: 437
Jen:

Your program works on my local network. Like your test case, I ran the echo server on Windows ME and the client on Windows 2000. I even copied your source code directly from your post and compiled it.

Now the stupid question -- well, not so stupid, since it bit me too. Your client uses TCP. Is the server a TCP server or a UDP server? When I first ran the test, I also got a 10061 error, but that was because I was running a UDP echo server. Then when I ran a TCP echo server, it worked fine.


BTW, I recognize the code as coming from Donahoo and Calvert's "Pocket Guide to TCP/IP Sockets: C Version" (second edition now titled "TCP/IP Sockets in C"). Good introductory book. It got me out of my "analysis paralysis" from researching the theory and got me coding and experimenting right away with their complete examples.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > sockets, echoclient, error 10061


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway