All pastes #285818 Raw Edit

Stuff

public text v1 · immutable
#285818 ·published 2006-12-20 02:03 UTC
rendered paste body
/* 
Programa que recibe un string de 512 caracteres
de una maquina a otra.

para la clase de programacion II.
Instituto Tecnologico de Ensenada.

20-Octubre 2006

por:  Joel Rodriguez.

Versamedium Web Services
http://www.versamedium.com 
 */





#include <sys/types.h>
#include <unistd.h>          
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>     /* socket command libraries needed by some compilers */
#include <winsock.h>

#define PORTNUM 1067 /* random port number, we need something */
#define SIM_LENGTH 2000 /* number of integers to be written and read */
#define MAX_MSG 1536
#define IP_ADDRESS "192.168.0.2"

/* code to establish a socket
 */

main()
{ 

SOCKET s;
char valstring[2000];
int bandera,manda,k,intval,portnum,connect,len,i,j,cuenta;
char datoc[512];
char payload[512];


  char   myname[256];
  struct sockaddr_in sa;
  struct hostent *hp;
  
   WORD wVersionRequested = MAKEWORD(1,1);
	WSADATA wsaData;
	int nRet,fin;
	short nPort;
    char *szServer;
    char ca;
    char foto[10000]; //para foto de 8,800 bytes logo.gif
                      // de google.com
                      
    FILE *imagen, *imagen2;
char buf[7];



  
printf("establish x\n");

printf("Versamedium Web Services. (client program) 2006\n");
printf("by: Joel Rodriguez joel@versamedium.com\n\n");


	portnum = 1067;
printf("establish 1xxx \n");

	//
	// Initialize WinSock and check the version
	//
	nRet = WSAStartup(wVersionRequested, &wsaData);
	if (wsaData.wVersion != wVersionRequested)
	{	
		fprintf(stderr,"\n Wrong version\n");
		//return;
	}


  memset(&sa, 0, sizeof(struct sockaddr_in)); /* clear our address */
  gethostname(myname, sizeof("192.168.0.2"));        /* who are we? */



 
printf("establish 2\n");  
  s = socket(AF_INET, SOCK_STREAM, 0);        /* create the socket */
  if (s == INVALID_SOCKET)
    return INVALID_SOCKET;
  
  
   printf("establish 1x %s\n",myname);
  hp = gethostbyname("192.168.0.2");                 /* get our address info */
  if (hp == NULL){  
         printf("establish 1xx %s\n",myname);                           /* we don't exist !? */
    return(INVALID_SOCKET);
      
                 }
  sa.sin_family = hp->h_addrtype;             /* this is our host address */
  sa.sin_port = htons(portnum);               /* this is our port number */ 
  
  
printf("establish 3\n");        
  /* bind the socket to the internet address */
  if (bind(s, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) ==
      SOCKET_ERROR) {
    closesocket(s);
    return(INVALID_SOCKET);
                    }
printf("establish 4\n");                     
  listen(s, 1);                               /* max # of queued connects */
  //return(s);

 len = sizeof(sa);
 /* hoy connect_sock = accept(sock, (struct sockaddr *)&serv_name, &len);*/
 connect = accept(s, (struct sockaddr *)&sa, &len);
                               //     (struct sockaddr *)&serv_name, &len);
  //  if (bind(sock, (struct sockaddr *)&serv_name, sizeof(serv_name)) < 0)
  /* send integers to the client's connected socket descriptor */


printf("Conexion Establecida 5\n");       


strcpy(valstring,"  128");   
    
    
//SOCKET new_sock = accept(s, NULL, NULL);

    
strcpy(valstring,"128");  
bandera=0;  
manda=1;			    
strcpy(datoc,"Hola profe,...");

printf("string 11? \n");   

/* Get the rest of the parameters */
/* Get the Parameters */
//read(s,(char *)payload ,4);

memset(&payload, 0, 512);

printf("caracteres entrada recv\n");

for(i=1;i<10000;i++){
//send(s,(char *)datoc,4,0);  

intval=recv(connect,(char *)payload ,512,0);
printf("valor regreso = %d\n\n",intval);
printf("%s\n",payload);


send(connect,(char *)datoc,512,0);  
}
printf("Termine presiona una tecla\n");

getchar();


}