Crea sito

Articoli con tag tcp

Client TCP with PHP

Here there is a simple example of tcp client written in php that tries to connect to a server, sends to it 2 messages and prints the server replies <?php /* Get the port for the WWW service. */ $service_port = getservbyname(‘www’, ‘tcp’); /*if you already know the destination port, you don’t need getservbyname, you can […]

Tags: , , ,

Server TCP with PHP

Here there is a simple example of tcp server written in php that accepts a connection from a client and for each message that the client sends to the server, it reply with the same message. <?php /* Allow the script to hang around waiting for connections. */ set_time_limit(0); /* Turn on implicit output flushing […]

Tags: , , ,

Received tcp packets from a socket (C language)

Here there is an example of a simple tcp receiver (server) #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #define SOCKET_ERROR   ((int)-1) #define SIZEBUF 1000000 void usage(void) {  printf (“usage: servTCP LOCAL_PORT_NUMBER\n”); exit(1); } int main(int argc, char *argv[]) { #define MAXSIZE 1000000 struct sockaddr_in […]

Tags: , , ,

Send tcp packet over socket (C language)

Here there is an example of a simple tcp sender #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #define SOCKET_ERROR   ((int)-1) #define SIZEBUF 1000000 void usage(void) {  printf (“usage: cliTCP REMOTE_IP_NUMBER REMOTE_PORT_NUMBER\n”); exit(1); } int main(int argc, char *argv[]) { #define MAXSIZE 1000000 struct sockaddr_in […]

Tags: , , ,