hello group,
i'm trying udp socket program. my code works fine with local host ip. i.e 127.0.0.1
according to my knowledge, if i change the ip address n give remote host's ip, two machines should communicate. it doesn't work. after runing server i checked port engaged with netstat. it shows perticular port in use.
please tell is there an other settings that i should look for?
thenk you.
8 1579
i couldn't find a solution for it yet. i have searched on net also. does anybody have a idea where shall i search for the solution at least?
thnks
Please can you post your code so we can see what's the problem and help you if possible?
Thanks!
yes sure andr3w. here is my code. - ///////////
-
client.cpp
-
////////////////////
-
-
#include <iostream>
-
#include <winsock2.h>
-
-
using namespace std;
-
#define SERVER_PORT 3000
-
#define BUF_SIZE 4096 // block transfer size
-
#define QUEUE_SIZE 20
-
#define IPAddress "127.0.0.1" // Local to the system - Loop back address
-
-
//#define IPAddress "192.168.1.11"
-
-
-
int main()
-
{
-
WORD wVersionRequested;
-
WSADATA wsaData;
-
SOCKADDR_IN server; //Socket address information
-
SOCKET s;
-
int err;
-
int bytesSent;
-
char buf[100] = "hi hello";
-
int addr_len = sizeof(struct sockaddr);
-
-
-
-
//--- INITIALIZATION -----------------------------------
-
wVersionRequested = MAKEWORD( 1, 1 );
-
err = WSAStartup( wVersionRequested, &wsaData );
-
-
if ( err != 0 ) {
-
printf("WSAStartup error %ld", WSAGetLastError());
-
WSACleanup();
-
return false;
-
}
-
//---------------------------------------------------------
-
-
-
//---- creat a server struct.--------
-
server.sin_family = AF_INET; // address family Internet
-
server.sin_port = htons (SERVER_PORT); //Port to connect on
-
server.sin_addr.s_addr = inet_addr (IPAddress); //Target IP
-
-
//--------------------------------------------------------
-
-
while(1) {
-
// ---- create SOCKET--------------------------------------
-
s = socket (AF_INET, SOCK_DGRAM, 0); //Create socket
-
if (s == INVALID_SOCKET)
-
{
-
printf("socket error %ld" , WSAGetLastError() );
-
getchar();
-
WSACleanup();
-
return false; //Couldn't create the socket
-
}
-
//---------------------------------------------------------
-
-
-
//---- SEND bytes -------------------------------------------
-
-
printf("trans buf:('q' to quit)\n");
-
gets_s(buf);
-
if ((strcmp(buf , "q") == 0) || strcmp(buf , "Q") == 0)
-
break;
-
bytesSent = sendto (s, buf, QUEUE_SIZE, 0, (struct sockaddr*) &server, sizeof(sockaddr));
-
if(bytesSent < 0 ){
-
printf("sendto fails with : %ld\n ", WSAGetLastError());
-
-
WSACleanup();
-
}
-
else
-
printf("bytes sent : %d\n" ,bytesSent );
-
//-------------------------------------------------------------------------
-
-
}
-
return 0;
-
}
- ////////////////////////
-
server.cpp
-
////////////////////////
-
-
#include <iostream>
-
#include <winsock2.h>
-
-
#define SERVER_PORT 3000
-
//#define BUF_SIZE 4096 // block transfer size
-
#define QUEUE_SIZE 20
-
#define IPAddress "127.0.0.1" // Local to the system - Loop back address
-
-
//#define IPAddress "127.0.0.85"
-
-
-
int main()
-
{
-
WORD wVersionRequested;
-
WSADATA wsaData;
-
SOCKET s;
-
struct sockaddr_in server, client; // holds IP address
-
char recvbuf[10] = {};
-
int b, opt;
-
int err;
-
int bytesRecv;//, bytesSent;
-
int addr_len = sizeof(struct sockaddr);
-
char *val = new char;
-
-
-
//--- INITIALIZATION -----------------------------------
-
wVersionRequested = MAKEWORD( 1, 1 );
-
err = WSAStartup( wVersionRequested, &wsaData );
-
-
if ( err != 0 ) {
-
printf("WSAStartup error %ld", WSAGetLastError());
-
WSACleanup();
-
return false;
-
}
-
//---------------------------------------------------------
-
-
//------------ server socket ----------------------------
-
server.sin_addr.s_addr = inet_addr(IPAddress);//htonl(INADDR_ANY);
-
server.sin_family = AF_INET; // address family Internet
-
server.sin_port = htons (SERVER_PORT); //Port to connect on
-
//-----------------------------------------------------------------
-
-
-
// ---- create SOCKET--------------------------------------
-
s = socket(AF_INET, SOCK_DGRAM, 0); //0 specifies to use appropriate protocol according to request
-
if (s < 0) {
-
printf("socket error %ld",WSAGetLastError() );
-
WSACleanup();
-
return false;
-
}
-
//--------------------------------------------------------
-
-
-
//---- BIND socket ----------------------------------------
-
b = bind(s, (struct sockaddr *) &server, sizeof(sockaddr));
-
if (b == -1) {
-
printf("socket bind error %ld",WSAGetLastError() );
-
WSACleanup();
-
getchar();
-
return false;
-
}
-
-
//----------------------------------------------------------
-
while (1) {
-
printf("\nwaiting for a connection\n");
-
-
-
//-----------receive bytes -------------------------------------------------------------
-
-
bytesRecv = recvfrom(s, recvbuf, QUEUE_SIZE, 0, (struct sockaddr *)&client, &addr_len );
-
-
if(bytesRecv < 0){
-
printf("\nbytesRecv : %d\n", bytesRecv);
-
printf("\nrecvfrom error : %ld\n", WSAGetLastError());
-
WSACleanup();
-
}
-
-
printf("connection ");
-
if ( bytesRecv == 0 || bytesRecv == WSAECONNRESET ) {
-
printf( "Closed.\n");
-
WSACleanup();
-
}
-
else printf("accepted\n");
-
printf("received from: %s \t port : %d\n ", inet_ntoa(client.sin_addr), ntohs(client.sin_port));
-
-
printf( " Bytes Recv: %s \n ", recvbuf );
-
-
//-----------------------------------------------------------------------------------------------
-
-
-
}
-
-
WSACleanup();
-
return 0;
-
}
see, here in this code if i replace loopback address with other machines ip address it should work. i mean that is what i cud know till now. please tell me if there are also other settings i should check like firewalls. actually i have kept firewall off.
thank you again.
i eve tried tcp client- server. same problem! :(
works with loop back address n not with network addresses.
hi..
your LAN activated Firewall means it generate TimedOut exception
so u check firewall settings tick On recommend radio button
hi shreeram,
i tried. no luck. :(
r u sure the code is correct?
can anybody please answer me?
ok. let me state my problem newly.
my client n server can send n receive data from labview's udp port. but not to each other.as, it can communicate with labview, the code is correct. but i can not send data through this c application. n i can not figure out why.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: pyguy2 |
last post by:
Issues of socket programming can be wierd, so I'm looking for some
comments.
In my python books I find exclusive use of socket.close(). From my
other readings, I know about a "partial close...
|
by: John Sheppard |
last post by:
Hi all,
I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
|
by: John Sheppard |
last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand.
Programming environment. VS.NET 2003, C#, Windows...
|
by: mscirri |
last post by:
The code below is what I am using to asynchronously get data from a
PocketPC device. The data comes in fine in blocks of 1024 bytes but
even when I send no data from the PocketPC constant blocks of...
|
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...
|
by: Uma - Chellasoft |
last post by:
Hai,
I am new to VB.Net programming, directly doing socket programming. In C, I
will be able to map the message arrived in a socket directly to a structure.
Is this possible in VB.Net. Can...
|
by: atlaste |
last post by:
Hi,
In an attempt to create a full-blown webcrawler I've found myself
writing a wrapper around the Socket class in an attempt to make it
completely async, supporting timeouts and some scheduling...
|
by: shonen |
last post by:
I'm currently attempting to connect to a shoutcast server
pull down the information from here and then I'll parse it.
I got this working with the httplib, which was great, the problem is I want...
|
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...
|
by: Stuart |
last post by:
I am in the process of teaching myself socket programming. I am
"playing around" with
some simple echo server-client programs for m the book TCP/IP Sockets
in C.
The Server program is:
...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |