Download TES9 Software Manual
Transcript
Example
The following code snippets are intended to demonstrate the use of winsock to communicate with
a LAN encoder.
/* declarations */
SOCKET s;
extern unsigned char rndata[1024];
char hostname[50];
char description[50];
char maxsockets[6];
char portnum[5];
char ipsend[20];
WORD wVersionRequired = 17;
/* 17 for winsock 1.1 or 2 for winsock 2.0 */
WSADATA wdata;
HOSTENT FAR *phostentm;
IN_ADDR in;
SOCKADDR_IN addr;
SOCKADDR_IN clientIn;
case WM_INITDIALOG:
{
WSAStartup(wVersionRequired,&wdata );
/* initialize winsock */
gethostname (hostname,sizeof(hostname)); /* get your computer’s name */
phostentm = gethostbyname(hostname);
/* get your computer’s IP number */
_fmemcpy(&in,phostentm->h_addr,4);
/* copy IP address of HOSTENT */
s = socket(AF_INET,SOCK_STREAM,0);
/* create socket */
WSAAsyncSelect(s,hWnd,WM_USER +100,FD_CONNECT); /* Non-blocking winsock */
addr.sin_family = AF_INET;
addr.sin_port = 0;
addr.sin_addr.s_addr = htonl(INADDR_ANY); /*allow connection from any port number*/
/* Bind the socket to our specifications */
bind(s,(LPSOCKADDR)&addr,sizeof(addr)); /* bind socket to above criteria */
strcpy(portnum, " 2000");
strcpy(ipsend, "102.102.102.102");
clientIn.sin_family = AF_INET;
clientIn.sin_port = htons(atoi(portnum));
/*fill in port number to send to */
clientIn.sin_addr.s_addr = inet_addr(ipsend); /*fill in IP address to send to */
/* make a connection on this socket */
connect(s, (LPSOCKADDR)&clientIn, sizeof(clientIn)); /* connect to destination */
}
TES9 Software User Manual (Iss. 02)
Appendix A. Software Interface for LAN • 9–3