%%ser.erl
-module(ser).
-export([server/0,start/2,stop/1]).
-behaviour(application).
%%数字类型
-define( UINT, 32/unsigned-little-integer).
-define( INT, 32/signed-little-integer).
-define( USHORT, 16/unsigned-little-integer).
-define( SHORT, 16/signed-little-integer).
-define( UBYTE, 8/unsigned-little-integer).
-define( BYTE, 8/signed-little-integer).
start(_type,Argu) ->
server().
%%启动服务并接受客户端的连接
server() ->
stop(S) ->
do_recv(LSock, []) ->
#include <netinet/in.h>
// for sockaddr_in
#include <sys/types.h>
// for socket
#include <sys/socket.h>
// for socket
#include <stdio.h>
// for printf
#include <stdlib.h>
// for exit
#include <string.h>
// for bzero>
#include <sys/time.h>
struct tem{
unsigned short int i;
unsigned short int j;
char p[4] ;
}temp;
int main(){
char buff[255];
struct sockaddr_in ser;
ser.sin_family = AF_INET;
ser.sin_port = htons(5678);
inet_aton("192.168.0.99",&ser.sin_addr);
//
temp.j = 20001;
strcpy(temp.p,"test");
int s_cli = socket(AF_INET,SOCK_STREAM,0);
if(!s_cli){
printf("socket init failed!\n");
exit(1);
}
int c_cli = connect(s_cli,(struct sockaddr *)&ser,sizeof(struct sockaddr));
if(c_cli<0){
printf("connect failed!\n");
exit(1);
}
int i = 1;
while(1){
int se_cli = send(s_cli,(void *)&temp,sizeof(temp),0);
if(!se_cli){
printf("send failed!\n");
}
printf("send...\n");
se_cli
= recv(s_cli,(struct temp *)buff,255,0);
buff[se_cli] = NULL;
printf("recv[%d]...:%s data_len:%d..\n",i++,buff,se_cli);
sleep(1);
}
return 0;
}