public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Plain win32 programming with sockets how?
  1999-01-31 23:52 Plain win32 programming with sockets how? Johan Compagner
@ 1999-01-31 23:52 ` Warren Young
  0 siblings, 0 replies; 2+ messages in thread
From: Warren Young @ 1999-01-31 23:52 UTC (permalink / raw)
  To: gnu-win32

At 11:27 AM 1/13/99 +0100, you wrote:
>How can i get the below code working without the need of the Cygwin?

[snip]

>     nbytes = write (sock, message, strlen (message));  

Use the send() call here: same syntax, but with a fourth argument, which is
usually 0.

>         perror ("write");

No perror under Win32.  Roll your own.  Example 10 in my FAQ (see link in
my signature) has a function that works roughly like perror, except that it
prints into a buffer instead of stdout, and only works with Winsock errors,
not general Win32 errors.

>     close (sock);  

closesocket().

Given those changes, your code should compile under any sane Win32 compiler.

Good luck,

= Warren Young -- Maintainer of the Winsock Programmer's FAQ at:
= http://www.cyberport.com/~tangent/programming/winsock/
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Plain win32 programming with sockets how?
@ 1999-01-31 23:52 Johan Compagner
  1999-01-31 23:52 ` Warren Young
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Compagner @ 1999-01-31 23:52 UTC (permalink / raw)
  To: gnu-win32

  
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@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-01-31 23:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-31 23:52 Plain win32 programming with sockets how? Johan Compagner
1999-01-31 23:52 ` Warren Young

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).