lopez1de
10-23-2008, 03:38 PM
It was a bit work to get into this, but finally it's working. :D
All the example I found aren't working on PPC, because gethostbyaddress try to get the host via DNS. DNS isn't supported on PPC (BT/WLAN). You have to set the IP address with another way as I did it.
To use this code you have to edit the winsock.ppl (for PPC).
#ifdef _WIN32_WCE
#define sockdll "ws2.dll"
To use this code you have to set the following globals:
global(server$,port$,serverSocket$);
server$ = "192.168.0.100";
port$ = 50555; // Integer! NOT string! ;-)
then add the network.ppl to you project and connect the client with:
client_connect;
client_connect returns true if the connection was successfull.
Now you can send strings to the client:
client_send("Hello Server! What's up?");
If the connection is broken, the client tries to reconnect automatically.
client_send returns the answer from the server as string.
This is the main part you will find in network.ppl. There are some important changes to swsock.ppl:
func client_connect
local(wsaData$,sockAddr$, mAddr$, host$);
struct(wsaData$, WSADATA);
if (WSAStartup(MAKEWORD(2, 2), &wsaData$) != 0)
showmessage("wsastartup: " + WSAGetLastErrorStr);
else
serverSocket$ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverSocket$ == INVALID_SOCKET)
showmessage("socket: " + WSAGetLastErrorStr);
else
new(mAddr$, TUINT);
mAddr$ = inet_addr(server$);
if (mAddr$ == INADDR_NONE)
showmessage("ip adress:" + WSAGetLastErrorStr);
closesocket(serverSocket$);
else
struct(sockAddr$, sockaddr_in);
sockAddr.sin_family$ = AF_INET;
sockAddr.sin_port$ = htons(port$);
sockAddr.sin_addr$ = mAddr$;
if (connect(serverSocket$, &sockAddr$, sizeof(sockAddr$)) == 0)
return(true);
else
showmessage("connect: " + WSAGetLastErrorStr);
closesocket(serverSocket$);
end;
end;
end;
end;
WSACleanup;
return(false);
end;
bye
All the example I found aren't working on PPC, because gethostbyaddress try to get the host via DNS. DNS isn't supported on PPC (BT/WLAN). You have to set the IP address with another way as I did it.
To use this code you have to edit the winsock.ppl (for PPC).
#ifdef _WIN32_WCE
#define sockdll "ws2.dll"
To use this code you have to set the following globals:
global(server$,port$,serverSocket$);
server$ = "192.168.0.100";
port$ = 50555; // Integer! NOT string! ;-)
then add the network.ppl to you project and connect the client with:
client_connect;
client_connect returns true if the connection was successfull.
Now you can send strings to the client:
client_send("Hello Server! What's up?");
If the connection is broken, the client tries to reconnect automatically.
client_send returns the answer from the server as string.
This is the main part you will find in network.ppl. There are some important changes to swsock.ppl:
func client_connect
local(wsaData$,sockAddr$, mAddr$, host$);
struct(wsaData$, WSADATA);
if (WSAStartup(MAKEWORD(2, 2), &wsaData$) != 0)
showmessage("wsastartup: " + WSAGetLastErrorStr);
else
serverSocket$ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverSocket$ == INVALID_SOCKET)
showmessage("socket: " + WSAGetLastErrorStr);
else
new(mAddr$, TUINT);
mAddr$ = inet_addr(server$);
if (mAddr$ == INADDR_NONE)
showmessage("ip adress:" + WSAGetLastErrorStr);
closesocket(serverSocket$);
else
struct(sockAddr$, sockaddr_in);
sockAddr.sin_family$ = AF_INET;
sockAddr.sin_port$ = htons(port$);
sockAddr.sin_addr$ = mAddr$;
if (connect(serverSocket$, &sockAddr$, sizeof(sockAddr$)) == 0)
return(true);
else
showmessage("connect: " + WSAGetLastErrorStr);
closesocket(serverSocket$);
end;
end;
end;
end;
WSACleanup;
return(false);
end;
bye