NO

Author Topic: error with simple sockets progrma  (Read 4674 times)

eagle3

  • Guest
error with simple sockets progrma
« on: May 12, 2009, 10:32:18 AM »
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


JohnF

  • Guest
Re: error with simple sockets progrma
« Reply #1 on: May 13, 2009, 10:10:23 AM »
I've corrected a few things but it does not connect for some reason.

Code: [Select]
#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


eagle3

  • Guest
Re: error with simple sockets progrma
« Reply #2 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



JohnF

  • Guest
Re: error with simple sockets progrma
« Reply #3 on: May 14, 2009, 08:10:57 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

eagle3

  • Guest
Re: error with simple sockets progrma
« Reply #4 on: May 14, 2009, 10:42:47 AM »
thnx jogn for ur reply


JohnF

  • Guest
Re: error with simple sockets progrma
« Reply #5 on: May 14, 2009, 11:37:22 AM »
We can try to sort the problem.

Exactly what errors are you getting?

John