hi there
i just work on a socket program and it's buggy
just halted at the first execution functions
the code file is attatched
plz tell me the error
I've corrected a few things but it does not connect for some reason.
#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#pragma comment(lib,"ws2_32.lib")
int main(void)
{
WSADATA wData;
struct sockaddr_in addr;
SOCKET sock;
char buf[256];
int ret = 0;
if (WSAStartup(0x202, &wData) != 0)
{
puts("Error INitializing WSA");
return GetLastError();
}
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock == INVALID_SOCKET)
{
puts("Error Creating socket");
return (-1);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(1234);
addr.sin_addr.s_addr = (unsigned long)inet_addr("192.168.1.17");
ret = connect(sock, (SOCKADDR *) &addr, sizeof(addr));
if (ret == -1)
{
puts("Error connecting");
return (-1);
}
send(sock, "Hello WOrld!", 15, 0);
recv(sock, buf, 256, 0);
closesocket(sock);
WSACleanup();
return (0);
}
John
ell john
thnx for u to help me
but it still do error when exectuing
cann't even run
Quote from: eagle3 on May 14, 2009, 07:33:28 AM
ell john
thnx for u to help me
but it still do error when exectuing
cann't even run
It runs here so I can't say why it doesn't for you. It prints ""Error connecting"
John
thnx jogn for ur reply
We can try to sort the problem.
Exactly what errors are you getting?
John