CS 5200 Distributed and Network Programming Fall 2005
Total Page:16
File Type:pdf, Size:1020Kb
CS 5200 Distributed and Network Programming Fall 2005
Winsock – sockets under Windows Since the socket API is a de facto standard in the networking industry, Microsoft has also adopted the socket API. there are only a few minor differences when using the socket API under Windows.
1. A different set of header files #include
3. A formal declaration of the SOCKET data type (as opposed to just int under Linux)
SOCKET s;
4. Under Linux, either the POSIX standard close() or the formal closesocket() functions may be used. Under Windows, you must use the formal closesocket() function.
Threads and Processes under Windows
Windows does not support the Linux fork() call to create a process. It does however, provide the _beginthread() function to create a thread. While implementation details are different, a thread is similar to a process with the following exceptions; a) A created thread shares global variables, file descriptors, and other system resources owned by the parent. b) A created thread may not replace its code page and must continue to share the parent’s code page. (NOTE: While _beginthread() allows passing of arguments to the new thread, use only explicit constants to avoid problems with shared variables.) The following example creates a new thread with the same stack size as the parent and begins execution at function thisfunc() with a single integer argument of 99;
_beginthread (( void (*)(void*)) addem, 0, (void *) 99); … void thisfunc (int x) {…
Determining an IP address
Under Windows, use a command prompt window and run the command ipconfig
> ipconfig
Under Linux, run the command ifconfig
$ ifconfig
08ceebc918953c360b2b36c10538f3e9.doc Page 1 4/26/2018