listentest.c
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define MYPORT 3490
#define BACKLOG 10
main()
{
int sockfd,new_fd;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int sin_size;
sockfd = socket(AF_INET,SOCK_STREAM,0);
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(MYPORT);
my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
bzero(&(my_addr.sin_zero),8);
bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr));
listen(sockfd,BACKLOG);
while(1)
{
sin_size=sizeof(struct sockaddr_in);
new_fd=accept(sockfd,&their_addr,&sin_size);
printf("get connected:/n");
printf("client IP adress:%s/n",inet_ntoa(their_addr.sin_addr));
printf(" port : %d/n",their_addr.sin_port);
}
exit(0);
}
connecttest.c
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define DEST_IP "127.0.0.1"
#define DEST_PORT 3490
main()
{
int sockfd;
struct sockaddr_in dest_addr;
sockfd=socket(AF_INET,SOCK_STREAM,0);
dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(DEST_PORT);
dest_addr.sin_addr.s_addr=inet_addr(DEST_IP);
bzero(&(dest_addr.sin_zero),8);
int ret=connect(sockfd,(struct sockaddr *)&dest_addr,sizeof(struct sockaddr));
if(ret==-1)
{
printf("error linking");
exit(0);
}
exit(0);
}
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define MYPORT 3490
#define BACKLOG 10
main()
{
int sockfd,new_fd;
struct sockaddr_in my_addr;
struct sockaddr_in their_addr;
int sin_size;
sockfd = socket(AF_INET,SOCK_STREAM,0);
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(MYPORT);
my_addr.sin_addr.s_addr=htonl(INADDR_ANY);
bzero(&(my_addr.sin_zero),8);
bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr));
listen(sockfd,BACKLOG);
while(1)
{
sin_size=sizeof(struct sockaddr_in);
new_fd=accept(sockfd,&their_addr,&sin_size);
printf("get connected:/n");
printf("client IP adress:%s/n",inet_ntoa(their_addr.sin_addr));
printf(" port : %d/n",their_addr.sin_port);
}
exit(0);
}
connecttest.c
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define DEST_IP "127.0.0.1"
#define DEST_PORT 3490
main()
{
int sockfd;
struct sockaddr_in dest_addr;
sockfd=socket(AF_INET,SOCK_STREAM,0);
dest_addr.sin_family=AF_INET;
dest_addr.sin_port=htons(DEST_PORT);
dest_addr.sin_addr.s_addr=inet_addr(DEST_IP);
bzero(&(dest_addr.sin_zero),8);
int ret=connect(sockfd,(struct sockaddr *)&dest_addr,sizeof(struct sockaddr));
if(ret==-1)
{
printf("error linking");
exit(0);
}
exit(0);
}