Mail Archives: djgpp/2001/05/21/18:00:06
Message-ID: | <001e01c0e241$6592e050$96f5edc8@Soft150>
|
From: | =?iso-8859-1?Q?J=FAlio_Adrian_Mi=F1o_Van_Helden?= <julio AT softplan DOT com DOT br>
|
To: | <djgpp AT delorie DOT com>
|
Subject: | Compiling socket client in win32 System
|
Date: | Mon, 21 May 2001 19:00:07 -0300
|
MIME-Version: | 1.0
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Mailer: | Microsoft Outlook Express 5.50.4133.2400
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4133.2400
|
Reply-To: | djgpp AT delorie DOT com
|
This is a multi-part message in MIME format.
------=_NextPart_000_001B_01C0E228.40366610
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I need to compile this ipc program on win32 but i can't find any port =
for socket.h on win32 system without change the code.
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>=20
#include <unistd.h>=20
#include <stdlib.h>=20
#include <stdio.h>=20
=20
main ( int argc, char *argv[ ] )=20
{=20
int cont,cria_socket;=20
int bufsize =3D 1024;=20
char *buffer =3D malloc(bufsize);=20
struct sockaddr_in address;=20
if ((cria_socket =3D socket(AF_INET,SOCK_STREAM,0)) > 0)=20
printf("O socket foi criado\n");
else
printf("Erro na cria=E7=E3o do Socket\n");
address.sin_family =3D AF_INET;=20
address.sin_addr.s_addr =3D INADDR_ANY;=20
address.sin_port =3D htons(80);=20
if (connect(cria_socket,(struct sockaddr *)&address, sizeof(address)) =
=3D=3D 0)=20
printf("A conexao Foi aceita\n");=20
else
printf("Conexao recusada\n");
=20
for (cont=3D1;cont<2;cont++)=20
{ =20
printf("Mensagem a enviar: ");
gets(buffer);=20
send(cria_socket,buffer,bufsize,0);=20
recv(cria_socket,buffer,bufsize,0);=20
printf("Mensagem recebida: %s\n",buffer);=20
}=20
close(cria_socket);=20
printf("Socket Fechado: ");=20
}=20
------=_NextPart_000_001B_01C0E228.40366610
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3103.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I need to compile this ipc program on =
win32 but i=20
can't find any port for socket.h on win32 system without change the=20
code.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>#include =
<sys/socket.h><BR>#include=20
<sys/types.h><BR>#include <netinet/in.h> <BR>#include=20
<unistd.h> <BR>#include <stdlib.h> <BR>#include =
<stdio.h>=20
<BR> <BR>main ( int argc, char *argv[ ] ) <BR>{ <BR> =
int=20
cont,cria_socket; <BR> int bufsize =3D 1024; =
<BR> char=20
*buffer =3D malloc(bufsize); <BR> struct sockaddr_in =
address;=20
<BR> if ((cria_socket =3D socket(AF_INET,SOCK_STREAM,0)) =
> 0)=20
<BR> printf("O socket foi =
criado\n");<BR> =20
else<BR> printf("Erro na cria=E7=E3o do=20
Socket\n");<BR> address.sin_family =3D AF_INET; =
<BR> =20
address.sin_addr.s_addr =3D INADDR_ANY; <BR> =
address.sin_port =3D=20
htons(80); <BR> if (connect(cria_socket,(struct sockaddr=20
*)&address, sizeof(address)) =3D=3D 0) <BR> =
printf("A=20
conexao Foi aceita\n"); <BR> =
else<BR> =20
printf("Conexao recusada\n");<BR> =
<BR> for=20
(cont=3D1;cont<2;cont++) <BR> { =20
<BR> printf("Mensagem a =
enviar:=20
");<BR> gets(buffer);=20
<BR> =20
send(cria_socket,buffer,bufsize,0);=20
<BR> =20
recv(cria_socket,buffer,bufsize,0);=20
<BR> printf("Mensagem =
recebida:=20
%s\n",buffer); </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> } =
<BR> =20
close(cria_socket); <BR> printf("Socket Fechado: "); <BR>}=20
</FONT></DIV></BODY></HTML>
------=_NextPart_000_001B_01C0E228.40366610--
- Raw text -