Chào mọi người,
Mình hiện đang code một chương trình nhỏ để giao tiếp giữa 2 máy dựa vào winsock, mình tham khảo code ở đây: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Sau khi code xong, mình dùng VS 2012 để build chương trình thành file .exe để chạy (or compile chạy thử) nhưng mà VS 2012 báo khá là nhiều lỗi về khai báo, vì mình chân ướt chân ráo nên cũng không biết làm thế nào, nay mong mọi người xem qua và giúp đỡ. Cảm ơn mọi người!

Code của mình
[+] https://pastebin.com/AAmVLTDB
[+] https://pastebin.com/K5dWEvHe

Còn đây là lỗi VS 2012 báo:


------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
wsTCPServer.c
c:\users\haniz\desktop\wstcpserver.c(55): error C2275: 'SOCKET' : illegal use of this type as an expression
c:\program files\windows kits\8.0\include\um\winsock2.h(111) : see declaration of 'SOCKET'
c:\users\haniz\desktop\wstcpserver.c(55): error C2146: syntax error : missing ';' before identifier 'ListenSocket'
c:\users\haniz\desktop\wstcpserver.c(55): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(56): error C2275: 'SOCKET' : illegal use of this type as an expression
c:\program files\windows kits\8.0\include\um\winsock2.h(111) : see declaration of 'SOCKET'
c:\users\haniz\desktop\wstcpserver.c(56): error C2146: syntax error : missing ';' before identifier 'ClientSock'
c:\users\haniz\desktop\wstcpserver.c(56): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(58): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(63): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(65): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(69): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(71): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(76): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(76): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(77): error C2065: 'ListenSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(84): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(86): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(89): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(91): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(101): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(108): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(111): error C2065: 'ClientSock' : undeclared identifier
c:\users\haniz\desktop\wstcpserver.c(116): error C2065: 'ClientSock' : undeclared identifier
wsTCPClient.c
c:\users\haniz\desktop\wstcpclient.c(9): error C2065: 'WSDATA' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(9): error C2146: syntax error : missing ';' before identifier 'wsaData'
c:\users\haniz\desktop\wstcpclient.c(9): error C2065: 'wsaData' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(10): error C2143: syntax error : missing ';' before 'type'
c:\users\haniz\desktop\wstcpclient.c(14): error C2143: syntax error : missing ';' before 'type'
c:\users\haniz\desktop\wstcpclient.c(17): error C2143: syntax error : missing ';' before 'type'
c:\users\haniz\desktop\wstcpclient.c(24): error C2065: 'argc' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(25): error C2065: 'PORT' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(25): error C2065: 'argv' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(25): error C2109: subscript requires array or pointer type
c:\users\haniz\desktop\wstcpclient.c(26): error C2065: 'HOST' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(26): error C2065: 'argv' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(26): error C2109: subscript requires array or pointer type
c:\users\haniz\desktop\wstcpclient.c(27): error C2065: 'msg' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(27): error C2065: 'argv' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(27): error C2109: subscript requires array or pointer type
c:\users\haniz\desktop\wstcpclient.c(30): error C2065: 'argv' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(30): error C2109: subscript requires array or pointer type
c:\users\haniz\desktop\wstcpclient.c(34): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(34): error C2065: 'wsaData' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(34): warning C4133: 'function' : incompatible types - from 'int *' to 'LPWSADATA'
c:\users\haniz\desktop\wstcpclient.c(35): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(40): error C2065: 'Cltsock' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(41): error C2065: 'Cltsock' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(41): error C2224: left of '.ai_family' must have struct/union type
c:\users\haniz\desktop\wstcpclient.c(42): error C2065: 'Cltsock' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(42): error C2224: left of '.ai_socktype' must have struct/union type
c:\users\haniz\desktop\wstcpclient.c(43): error C2065: 'Cltsock' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(43): error C2224: left of '.ai_protocol' must have struct/union type
c:\users\haniz\desktop\wstcpclient.c(46): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(46): error C2065: 'argv' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(46): error C2109: subscript requires array or pointer type
c:\users\haniz\desktop\wstcpclient.c(46): error C2065: 'PORT' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(46): warning C4047: 'function' : 'PCSTR' differs in levels of indirection from 'int'
c:\users\haniz\desktop\wstcpclient.c(46): warning C4024: 'getaddrinfo' : different types for formal and actual parameter 1
c:\users\haniz\desktop\wstcpclient.c(46): error C2065: 'Cltsock' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(46): warning C4133: 'function' : incompatible types - from 'int *' to 'PCSTR'
c:\users\haniz\desktop\wstcpclient.c(46): error C2065: 'result' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(46): warning C4133: 'function' : incompatible types - from 'int *' to 'const ADDRINFOA *'
c:\users\haniz\desktop\wstcpclient.c(46): error C2198: 'getaddrinfo' : too few arguments for call
c:\users\haniz\desktop\wstcpclient.c(47): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(53): error C2275: 'SOCKET' : illegal use of this type as an expression
c:\program files\windows kits\8.0\include\um\winsock2.h(111) : see declaration of 'SOCKET'
c:\users\haniz\desktop\wstcpclient.c(53): error C2146: syntax error : missing ';' before identifier 'ConnectSocket'
c:\users\haniz\desktop\wstcpclient.c(53): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(55): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(55): error C2065: 'result' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(55): error C2223: left of '->ai_family' must point to struct/union
c:\users\haniz\desktop\wstcpclient.c(55): error C2223: left of '->ai_socktype' must point to struct/union
c:\users\haniz\desktop\wstcpclient.c(55): error C2223: left of '->ai_protocol' must point to struct/union
c:\users\haniz\desktop\wstcpclient.c(55): error C2198: 'socket' : too few arguments for call
c:\users\haniz\desktop\wstcpclient.c(57): error C2198: 'freeaddrinfo' : too few arguments for call
c:\users\haniz\desktop\wstcpclient.c(63): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(63): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(63): error C2065: 'result' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(63): error C2223: left of '->ai_addr' must point to struct/union
c:\users\haniz\desktop\wstcpclient.c(63): error C2223: left of '->ai_addrlen' must point to struct/union
c:\users\haniz\desktop\wstcpclient.c(63): error C2198: 'connect' : too few arguments for call
c:\users\haniz\desktop\wstcpclient.c(64): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(65): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(69): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(69): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(69): error C2065: 'msg' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(69): warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
c:\users\haniz\desktop\wstcpclient.c(69): warning C4024: 'send' : different types for formal and actual parameter 2
c:\users\haniz\desktop\wstcpclient.c(69): warning C4024: 'strlen' : different types for formal and actual parameter 1
c:\users\haniz\desktop\wstcpclient.c(71): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(76): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(79): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(81): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(88): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(88): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(88): error C2065: 'recvbuf' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(88): warning C4047: 'function' : 'char *' differs in levels of indirection from 'int'
c:\users\haniz\desktop\wstcpclient.c(88): warning C4024: 'recv' : different types for formal and actual parameter 2
c:\users\haniz\desktop\wstcpclient.c(89): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(90): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(92): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(98): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(101): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(101): error C2065: 'Connection' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(102): error C2065: 'iResult' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(104): error C2065: 'ConnectSocket' : undeclared identifier
c:\users\haniz\desktop\wstcpclient.c(109): error C2065: 'ConnectSocket' : undeclared identifier
Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========