As you can tell by my code that I will post I am obviously new with linux
socket programming so to be to hard on me :)
When I run my little program I get this error:
Server: got connection from 192.168.0.5
recv: Transport endpoint is not connected.
I don't know what that means or why I am getting it.
I know the connection is made by the server: message.
My other end program is a VB program. When i uncomment out the appropriate
lines in the following code my VB app works just find for receiving
messages.
Thanks -
-
/*
-
** server.c -- a stream socket server demo
-
*/
-
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <unistd.h>
-
#include <errno.h>
-
#include <string.h>
-
#include <sys/types.h>
-
#include <sys/socket.h>
-
#include <netinet/in.h>
-
#include <arpa/inet.h>
-
#include <sys/wait.h>
-
#include <signal.h>
-
#include <string.h>
-
-
#define MYPORT 3490
-
-
#define BACKLOG 10
-
-
#define MAXDATASIZE 100
-
-
void sigchld_handler(int s)
-
{
-
while(wait(NULL) > 0);
-
}
-
-
int main(void)
-
{
-
int sockfd, new_fd;
-
struct sockaddr_in my_addr;
-
struct sockaddr_in their_addr;
-
int sin_size;
-
struct sigaction sa;
-
int yes=1;
-
char msg[200]={""};
-
int msgLen;
-
int numbytes;
-
char buf[MAXDATASIZE];
-
-
-
-
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0))== -1) {
-
perror("socket");
-
exit(1);
-
}
-
-
if
-
(setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int))== -1) {
-
perror("setsockopt");
-
exit(1);
-
}
-
-
my_addr.sin_family = AF_INET;
-
my_addr.sin_port = htons(MYPORT);
-
my_addr.sin_addr.s_addr = INADDR_ANY;
-
memset(&(my_addr.sin_zero), '\0', 8);
-
-
if (bind(sockfd, (struct sockaddr *)&my_addr,sizeof(struct
-
sockaddr)== -1)
-
{
-
perror("bind");
-
exit(1);
-
}
-
-
if (listen(sockfd, BACKLOG) == -1) {
-
perror("listen");
-
exit(1);
-
}
-
-
sa.sa_handler = sigchld_handler;
-
sigemptyset(&sa.sa_mask);
-
sa.sa_flags = SA_RESTART;
-
if (sigaction(SIGCHLD, &sa, NULL) == -1) {
-
perror("sigaction");
-
exit(1);
-
}
-
sin_size = sizeof(struct sockaddr_in);
-
if ((new_fd = accept(sockfd, (structsockaddr *)&their_addr,
-
&sin_size)) == -1)
-
{
-
perror("accept");
-
}
-
printf("server: got connection
-
from%s\n",inet_ntoa(their_addr.sin_addr));
-
while(1)
-
{
-
// This code works great sending a message to my other VB
-
app
-
//*********************************************
-
//printf("Enter a message to sent: ");
-
//gets(msg);
-
//msgLen=strlen(msg);
-
// if (send(new_fd, msg, msgLen, 0) ==-1)
-
// perror("send");
-
//********************************************
-
-
//this is the code that doesnt work
-
//*********************************************************************
-
-
if ((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) ==-1)
-
{
-
perror("recv");
-
exit(1);
-
}
-
-
buf[numbytes] = '\0';
-
-
printf("Received: %s\n",buf);
-
-
}
-
//************************************************************************
-
return 0;
-
}
-
-
-
3 5985
Robert Smith wrote: As you can tell by my code that I will post I am obviously new with linux socket programming so to be to hard on me :)
When I run my little program I get this error: Server: got connection from 192.168.0.5 recv: Transport endpoint is not connected.
I don't know what that means or why I am getting it. I know the connection is made by the server: message.
My other end program is a VB program. When i uncomment out the appropriate lines in the following code my VB app works just find for receiving messages.
/* ** server.c -- a stream socket server demo */
#include <stdio.h> #include <stdlib.h> #include <unistd.h>
Not a standard include file
#include <errno.h> #include <string.h> #include <sys/types.h>
Not a standard include file
#include <sys/socket.h>
Not a standard include file
#include <netinet/in.h>
Not a standard include file
#include <arpa/inet.h>
Not a standard include file
#include <sys/wait.h>
Not a standard include file
#include <signal.h> #include <string.h>
With all those errors we cannot possibly understand your
non-portable code here. Try a newsgroup that deals with your
actual system.
--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - Bush.
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02
> if (bind(sockfd, (struct sockaddr *)&my_addr,sizeof(struct sockaddr)== -1) { perror("bind"); exit(1); }
Here the bind arguments are not proper. The third argument should
contain the size of the address structure whichis sizeof(my_addr).
On Sun, 05 Sep 2004 16:12:03 GMT, "Robert Smith" <no**@none.com>
wrote: As you can tell by my code that I will post I am obviously new with linux socket programming so to be to hard on me :)
Sockets, and (other) Linux specifics, are offtopic in clc, which deals
with standard/portable C. Try comp.unix.programming or (I think it is)
comp.os.linux.development.apps. But:
<snip> if ((new_fd = accept(sockfd, (structsockaddr *)&their_addr, &sin_size)) == -1)
<snip> // if (send(new_fd, msg, msgLen, 0) ==-1)
<snip> if ((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) ==-1)
Think about which fd is which.
- David.Thompson1 at worldnet.att.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom Jones |
last post by:
I need to access databases on both win2k and Linux systems but I have to set
up the DSNs under program control ... no uses using GUIs ...
Has anyone done this? if so can we discuss it either in...
|
by: Google Mike |
last post by:
After a lot of thought and research, and playing with FreeTDS and
InlineTDS, as well as various ODBC connections, I have determined that
the fastest and cheapest way to get up and going with PHP on...
|
by: gurtd_dauberie |
last post by:
I can't get the correct IP address on Linux...
The following code works properly on Windows and Unix.
But on Linux, I always get the Loopback Address (127.0.0.1)
Here is the code :
//gets the...
|
by: xunil |
last post by:
hi, could any one please help show me how to run a python script in
linux ?
when i try "python script.py" it just does nothing
this is the script iam trying to run
#!/usr/bin/env python...
|
by: 8anos |
last post by:
Hello,
I am new at the community and newbie at programming :)
As you may know rapidshare provides a perl script for linux, to upload files at their servers.
You can find the original scripts at...
| |
by: ganeshp |
last post by:
Hi ,
In Java using socket programming is it possible to have a server program on windows that services a client program on linux?
I tried the code in the below given link:...
|
by: getafixx |
last post by:
Hello everyone,
We have a linux server (Fedora core 7, default install, firewall turned off) and a bunch of windows XP machines on network/domain.
All machines are visible and I can get to both...
|
by: TsanChung |
last post by:
I want to make a java TCP socket client to communicate with a TCP
server socket on linux.
Are there some sample C unix server and java client socket programs
available?
The Richard Stevens'...
|
by: The Doctor |
last post by:
Hey people,
I have two applications:
the server, which creates a server socket, waits for a real-time signal,
and if it receives one, it creates a client socket.
The client, which will...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |
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: 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,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
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...
| |