#include <winsock2.h>
#include <stdio.h>
#include <string.h>
#include <io.h>
Go to the source code of this file.
◆ END_LINE
◆ ERROR
◆ MAX_MSG
◆ SERVER_PORT
◆ SUCCESS
◆ main()
Definition at line 29 of file tcpsvr.c.
29 {
30
31 WORD wVersionRequested;
34 int sd, newSd, cliLen;
35
38
40
43 printf(
"Could not initialize winsock dll.\n");
45 }
46
47
50 perror(
"cannot open socket ");
53 }
54
55
59
61 perror(
"cannot bind port ");
64 }
65
67
68 while(1) {
69
71 "To start test, Please telnet to localhost (127.0.0.1) port 23 \n"
72 "When connected input raw data followed by End of Line\n"
74
75 cliLen = sizeof(cliAddr);
77 if(newSd<0) {
78 perror(
"cannot accept connection ");
81 }
82
83
85
86
88
89 printf(
"%s: received from %s:TCP%d : %s\n",
argv[0],
92
94
95 }
96
97 }
98
99}
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
int PASCAL FAR WSACleanup(void)
◆ read_line() [1/2]
◆ read_line() [2/2]
int read_line |
( |
int |
newSd, |
|
|
char * |
line_to_return |
|
) |
| |
Definition at line 114 of file tcpsvr.c.
114 {
115
116 static int rcv_ptr=0;
120
122
123 while(1) {
124 if(rcv_ptr==0) {
125
129 perror(
" cannot receive data ");
132 printf(
" connection closed by client\n");
136 }
137 }
138
139
140
141
142
143
144 while(*(rcv_msg+rcv_ptr)!=
END_LINE && rcv_ptr<
n) {
147 rcv_ptr++;
148 }
149
150
152
154 rcv_ptr=0;
156 }
157
158
160
162 rcv_ptr++;
164 }
165
166
167
169 rcv_ptr = 0;
170 }
171
172 }
173}
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
#define memcpy(s1, s2, n)