OK....
have a try with this for the client;
Code:
#include <winsock2.h>
#include <stdio.h>
#define PORT 3550
#define MAXDATASIZE 100
struct hostent *he;
struct sockaddr_in server;
int numbytes;
char buf[MAXDATASIZE];
WSADATA wsdata;
SOCKET sock;
DWORD wsock;
int main(void)
{
WSAStartup(0x0101,&wsdata);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
he = gethostbyname("localhost");
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
if(connect(sock,(struct sockaddr *)&server,sizeof(server))==SOCKET_ERROR)
{
MessageBox(0,"Connect Error","",MB_OK);
return 0;
}
numbytes = recv(sock, buf, MAXDATASIZE, 0);
buf[numbytes] = '\0';
MessageBox(0,buf,"Server response:",MB_OK);
closesocket(sock);
WSACleanup();
return 1;
}
now the server;
Code:
#include <winsock2.h>
#include <stdio.h>
#define PORT 3550
#define BACKLOG 1
struct sockaddr_in server;
struct sockaddr_in client;
int sin_size;
WSADATA wsdata;
SOCKET sock1, sock2;
DWORD wsock;
char success[] = "This Msg Is From The Server", buf[50];
int r;
int main(void){
WSAStartup(0x0101,&wsdata);
sock1 = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr.s_addr = INADDR_ANY;
bind(sock1,(struct sockaddr*)&server,sizeof(struct sockaddr));
listen(sock1, BACKLOG);
sin_size = sizeof(struct sockaddr_in);
sock2 = accept(sock1,(struct sockaddr *)&client,&sin_size);
printf("Client connected to server.");
r = send(sock2,success,strlen(success),0); // send msg to client
closesocket(sock1);
closesocket(sock2);
WSACleanup();
return 1;
}
Compile them both as consoles (didnt use winmain cuz I'm lazy). Make sure you add the WS2_32.lib to both projects.
Run server in console window (should just hang there). Then run client in another console window. The server window should finish running and display "Client connected to server.". There should also be a messagebox with a string passed from the server to the client - I think this is what you were after.
I quickly tested it on my PC and it seems to work, but if not then say.