Windows socket communication program – Solvline PB2xxxUG User Manual
Page 96

//Transmits a data packet to the opened socket by creating the data packet.
//Calls it in the main function every 3 seconds.
void SendData(void)
{
int
i;
char temp[30] = "This is LoopBack Data!”
// Outputs data to the ttys0.
write(porthandle, temp, sizeof(temp));
}
//Outputs received data on the screen.
void GetData(void)
{
int
i;
char
readbuff[255];
// Reads data.
readval = read(porthandle, readbuff, sizeof(readbuff));
if (readval < 1) return;
readbuff[readval] = 0;
printf("%s",readbuff);
}
//Opens the ttys0 port of RTCP connected to Portbase.
void OpenSerial(void)
{
int
i;
// Opens the ttys0 port.
porthandle = open(“/dev/ttys0”, O_RDWR | O_NOCTTY |O_NONBLOCK);
// Outputs an error if the socket port is not valid.
if (porthandle < 0){
printf("Can not Open %s\n", ComName);
}
}
3. Windows Socket Communication Program
Basically, the Portbase operates network communication through the socket.
The socket is an effective way to communicate on a network between the client and server.
Programming steps for the socket communication are as follows.
The initial handshaking to support socket communication consist of two methods, Passive and Active.
96