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 5996
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,size of(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.co m>
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.progr amming or (I think it is)
comp.os.linux.d evelopment.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.ne t 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 here or offline?
thanks
Tom
|
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 Linux,
connecting to MS SQL Server, unless it was already pre-installed by
your Linux installation, is to build your own multithreaded TCP socket
server on Windows and connect to it through the socket API in PHP on
Linux (if you have installed...
|
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 IP via InetAddress class
//works on UNIX and WIN, but not on LINUX !!
InetAddress hostIP = InetAddress.getLocalHost();
String hostIPStr = hostIP.getHostAddress();
|
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
"USAGE: echoserver.py <port>"
|
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 rapidshare news :
http://images.rapidshare.com/software/rsapi.pl
If you test it you will see that you can upload one file at time.
I try to modify it in that way that script can read a text file with the names of the files i want to...
| |
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:
http://williams.comp.ncat.edu/Networks/JavaSocketExample.htm
This does not work when the client program is on a Linux machine.
Error:
Error Connection refused
|
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 windows and linux by various methods.
We are trying to resolve a problem of not being able to connect to the linux box from the xp machines using python XMLRPC. (This is the module used in the software I am trying to set up)
Python is at 2.4...
|
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' "Unix network programming" book described a TCP
server (tcpcliserv04.c) and client (tcpcli04.c). I compiled and
executed them successfully as follows:
$ tcpcliserv04 &
|
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 connect to the server. This will generate a real-
time signal at the server, who will create a client socket for this
client.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |