Ejemplo n.º 1
0
/* Programa principal. Abre la conexión, recibe su número de cliente y
 * luego envía dicho número cada segundo */
main()
{
	int sock;		/* descriptor de conexión con el servidor */
	int buffer;		/* buffer de lectura de datos procedentes del servidor */
	int error;		/* error de lectura por el socket */

	/* Se abre una conexión con el servidor */
	sock = Abre_Conexion_Inet ("localhost", "8000");

	/* Se lee el número de cliente, dato que nos da el servidor. Se escribe
	 * dicho número en pantalla.*/
	error = Lee_Socket (sock, (char *)&buffer, sizeof(int));

	/* Si ha habido error de lectura lo indicamos y salimos */
	if (error < 1)
	{
		printf ("Me han cerrado la conexión\n");
		exit(-1);
	}

	/* Se escribe el número de cliente que nos ha enviado el servidor */
	printf ("Soy cliente %d\n", buffer);

	/* Bucle infinito. Envia al servidor el número de cliente y espera un
	 * segundo */
	while (1)
	{
		Escribe_Socket (sock, (char *)&buffer, sizeof(int));
		sleep (1);
	}
}
Ejemplo n.º 2
0
//informa si acepto o rechazo la conexion
void fd_mensaje(const int socket, const int header_mensaje, const char *msj,
		int *env) {
	t_send t_send;

	if(socket <0){
		log_in_disk_mensajes(LOG_LEVEL_ERROR,
										" \t\t socket invalidos t %d y tipo de mensaje %d " ,socket,header_mensaje,msj);

		exit(1);
	}


	memset(t_send.mensaje, '\0', max_len);
	strcpy(t_send.mensaje, msj);
	t_send.header_mensaje = header_mensaje;
	t_send.payLoadLength = strlen(t_send.mensaje) + 1;

	*env = Escribe_Socket(socket, &t_send,
			sizeof(t_header) + t_send.payLoadLength);

	log_in_disk_mensajes(LOG_LEVEL_INFO,
								" \t\t entro an fd_mensaje con el socket %d y tipo de mensaje %d el mensaje a enviar es %s byts enviados %d" ,socket,header_mensaje,msj,*env);

}
Ejemplo n.º 3
0
int EnviarAngulos(ANGULOS *ang, int Socket){

	Escribe_Socket (Socket, (char *) ang, sizeof (ANGULOS));

}
Ejemplo n.º 4
0
void MyFrame::AZPCliente(wxCommandEvent& event)
{
	wxMessageBox("Modo experimental\nSe recomienda no usar hasta otras actualizaciones","Divel Network",wxICON_WARNING|wxOK);
	int siono=wxMessageBox("Quieres utilizar IPv6?\nSi no se usara IPv4","Divel Network",wxICON_QUESTION|wxYES_NO);

	if(siono==wxNO){
	
	char Cadena[1024];
	char ip[1024];
	char nombreCliente1[1024];
	char nombreCliente2[1024];
	wxString wxip=wxGetTextFromUser("Introduce la IP del server de Azpazeta","Divel Network","127.0.0.1");	
	strncpy(ip, (const char*)wxip.mb_str(wxConvUTF8), 1023);
	struct sockaddr_in Direccion;
	struct servent *Puerto;
	struct hostent *Host;
	Direccion.sin_addr.s_addr=inet_addr(ip);
	Direccion.sin_family = AF_INET;
	Direccion.sin_port = 6996;
	AZPServer = socket (AF_INET, SOCK_STREAM, 0);
	connect (AZPServer, (struct sockaddr *)&Direccion, sizeof (Direccion));
	Lee_Socket(AZPServer, Cadena,1024);
	wxMessageBox(wxString::Format("%s",Cadena),"Server informa",wxICON_INFORMATION|wxOK);
	wxString onlinename=wxGetTextFromUser("Introduce tu nombre online","Divel Network","");
	strncpy(nombreCliente1, (const char*)onlinename.mb_str(wxConvUTF8), 1023);
	Escribe_Socket(AZPServer, nombreCliente1, 1024);
	Lee_Socket(AZPServer, nombreCliente2, 1024);
	wxMessageBox(wxString::Format("El otro jugador es: %s",nombreCliente2),"Divel Network");
}else{
	//IPv6
	char Cadena[1024];
	char ip[1024];
	char nombreCliente1[1024];
	char nombreCliente2[1024];
	wxString wxip=wxGetTextFromUser("Introduce la IPv6 del server de Azpazeta","Divel Network","::1");	
	strncpy(ip, (const char*)wxip.mb_str(wxConvUTF8), 1023);
	struct sockaddr_in6 Direccion;
	struct servent *Puerto;
	struct hostent *Host;
	//Direccion.sin6_len = sizeof(Direccion);
	//unsigned char ipv6[16]="::1";
	inet_pton(PF_INET6, ip,&(Direccion.sin6_addr));
	//Direccion.sin6_addr.s6_addr=inet_pton();	
	//Direccion.sin6_addr.s6_addr=inet_addr6(ip);
	Direccion.sin6_family = AF_INET6;
	Direccion.sin6_port = 6996;
	AZPServer = socket (AF_INET6, SOCK_STREAM, 0);
	connect (AZPServer, (struct sockaddr *)&Direccion, sizeof (Direccion));
	Lee_Socket(AZPServer, Cadena,1024);
	wxMessageBox(wxString::Format("%s",Cadena),"Server informa",wxICON_INFORMATION|wxOK);
	wxString onlinename=wxGetTextFromUser("Introduce tu nombre online","Divel Network","");
	strncpy(nombreCliente1, (const char*)onlinename.mb_str(wxConvUTF8), 1023);
	Escribe_Socket(AZPServer, nombreCliente1, 1024);
	Lee_Socket(AZPServer, nombreCliente2, 1024);
	wxMessageBox(wxString::Format("El otro jugador es: %s",nombreCliente2),"Divel Network");
}
	AZPServerData datos;
	MyEstado myestado;
	datos.money=money;
	datos.level=level;
	datos.city=city;
	datos.name="A";
	datos.droga=droga;
	datos.blacklist=blacklist;
	datos.socio=socio;
	datos.electro=electro;
	datos.food=food;
	datos.textil=textil;
	datos.sobornos=sobornos;
	datos.mision=mision;
	datos.rich=rich;
	write(AZPServer, &datos, sizeof(datos));
	read(AZPServer, &myestado, sizeof(myestado));
	if(myestado.bien==true){wxMessageBox(wxString::Format("Bien, el otro tienen menos, concretamente: %d", myestado.moneyotro));}
	if(myestado.bien==false){wxMessageBox(wxString::Format("Mal, el otro tiene mas, concretamente: %d", myestado.moneyotro));}
	//close(AZPServer);
	wxTimer* timer;
	timer=new wxTimer(this, TIMER_ID);
	timer->Start(60000, false);
	wxMessageBox(wxT("Empezando nueva partida"), wxT("Azpazeta"),wxICON_INFORMATION|wxOK);
	newname=wxGetTextFromUser(wxT("Introduce tu nombre para la partida"),wxT("Azpazeta"),wxT(""));
	wxBitmap bocadillo("/opt/extras.ubuntu.com/azpazeta/media/Bocadillo.png",wxBITMAP_TYPE_PNG);
	Bocadillo=new wxStaticBitmap(panel, ID_DIBUJO, bocadillo, wxPoint(600,450));
	cap1mis1=new wxStaticText(panel, ID_DIBUJO, wxT(CAP1MIS1TEX1), wxPoint(625, 470));
	actualizar=new wxButton(panel, wxID_ANY, "...");
	jugar=new wxButton(panel, wxID_ANY, "...");
	instrucciones=new wxButton(panel, wxID_ANY, "...");
	city=1;
	Adrix->Destroy();
	money=2000;
	mision=0;
	level=0;
	MyFrame::Stage1();

}