Mail Archives: cygwin/1999/01/13/16:27:02
From: | joco AT wxs DOT nl (Johan Compagner)
|
Subject: | Plain win32 programming with sockets how?
|
13 Jan 1999 16:27:02 -0800
: | |
Message-ID: | <002601be3edf$5db896c0$05ff79c3.cygnus.gnu-win32@joco.wxs.nl>
|
Mime-Version: | 1.0
|
To: | <gnu-win32 AT cygnus DOT com>
|
hi,
How can i get the below code working without the need of the Cygwin?
i also hoop that the exe size can be a bit smaller, it is now 300K
I tried to include <windows.h> <windows32\sockets.h> and drop the sys/socket and netinet/in
because those files generates many errors with -mno-cygwin option.
gcced with : gcc -mno-cygwin -lwsock32 test.c
i think that if you don't use cygwin you must use winsock it self am i right?
so the -lwsock32 is neccesary?
thx for you support.
Johan Compagner
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT 7080
int main(int argc, char *argv[])
{
int sock;
char* adres = "127.0.0.1";
int nbytes;
char* message;
char* hostname = (char*)malloc(sizeof(char[14]));
struct sockaddr_in name;
struct hostent *host;
if(argc < 2)
{
printf ("Wrong Usage: <adres> java_program_to_start");
return 0;
}
if(argc > 2)
{
adres = argv[1];
message = argv[2];
}
else message = argv[1];
gethostname (hostname, strlen (hostname));
/* Create the socket. */
sock = socket (PF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
perror ("socket (client)");
return 1;
}
/* Connect to the server. */
name.sin_family = AF_INET;
name.sin_port = htons (PORT);
name.sin_addr.s_addr = inet_addr(adres);
if (0 > connect (sock,(struct sockaddr *) &name,sizeof (name)))
{
perror ("connect (client)");
return 1;
}
/* Send data to the server. */
nbytes = write (sock, message, strlen (message));
if (nbytes < 0)
{
perror ("write");
return 1;
}
close (sock);
printf("launched %s at %s (%s)", message , hostname ,inet_ntoa(name.sin_addr));
return 0;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -