Forum > Other

Winsock and OS/2 Strange Issue

(1/4) > >>


I've messed with this for days, googled it, asked bing, searched this forum etc.

I'm writing a Internet BBS in freepascal under OS/2.  Why?  Because it's there and I'm bored with Ruby (already wrote a multithreaded BBS for Ruby and one in TP6 back in the day)... so, I'm working on a multi-threaded server, which is coming along (so far)... but... I can't get this thing to give me the correct address of a connecting client.  Here is sample code (not the server but my test spike) that gives me weird addresses under OS/2, but works FINE under Windows 11.

Under OS/2 I get:

Server is listening on port 1234
Accepted a connection from

On Windows:
Server is listening on port 1234
Accepted a connection from

I don't get it. 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- {This is a TCP server using PMWsock}program TCPServer; uses  Winsock, SysUtils; const  SERVER_PORT = 1234; {Arbitrary port number}  MAX_CLIENTS = 10; {Maximum number of concurrent clients} var  WSAData: TWSAData;  ServerSocket, ClientSocket: TSocket;  ServerAddr, ClientAddr: TSockAddr;  CommAddr : SockAddr;  Buffer: array[0..255] of Char;  BytesSent, BytesRecv: Integer;  Message: String;  ClientAddrSize: Integer;  CommAddrSize : LongInt;  CommLen: LONGINT;  i : integer;  output :string;begin  {Initialize Winsock}  WSAStartup($0101, WSAData);  {Create a socket}  ServerSocket := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);  {Bind the socket to a port}  ServerAddr.sin_family := AF_INET;  ServerAddr.sin_port := htons(SERVER_PORT);  ServerAddr.sin_addr.S_addr := INADDR_ANY;  bind(ServerSocket, ServerAddr, SizeOf(ServerAddr));  {Listen for incoming connections}  listen(ServerSocket, MAX_CLIENTS);  WriteLn('Server is listening on port ', SERVER_PORT);  {Accept a connection from a client}  ClientAddrSize := SizeOf(ClientAddr);  ClientSocket := accept(ServerSocket, @ClientAddr, @ClientAddrSize);  WriteLn('Accepted a connection from ', inet_ntoa(ClientAddr.sin_addr));  CommLen := Sizeof(CommAddr);  Writeln('ERROR: ', getpeername(ClientSocket, CommAddr,CommLen));  Writeln('Server Socket: ',ServerSocket);  Writeln('Client Socket: ',ClientSocket);  writeln('Last Error: ', WSAGetLastError);  Writeln('Connected IP: ');  For i := 0 to 13 do    BEGIN     write(commaddr.sa_data[i]); write(' ');    END;    Writeln;    Writeln('sa_family: ',commaddr.sa_family);    Writeln(strpas(inet_ntoa(PSockAddrIn(@CommAddr.sa_data)^.sin_addr)));  {Receive a message from the client}  BytesRecv := recv(ClientSocket, Buffer, SizeOf(Buffer), 0);  Buffer[BytesRecv] := #0;  WriteLn('Received: ', Buffer);  {Send a message to the client}  Message := 'Hello, this is a TCP server';  {BytesSent := send(ClientSocket, Message[1], Length(Message), 0);}  {Close the client socket}  closesocket(ClientSocket);  {Close the server socket}  closesocket(ServerSocket);  {Clean up Winsock}  WSACleanup;end. 

Thaddy: is USA so maybe your external IP address?

That's a reasonable theory but I live in the UK.

I've checked... Mine starts with 86...


--- Quote from: NeddieSeagoon on February 12, 2024, 04:42:25 pm ---{This is a TCP server using PMWsock}
--- End quote ---

Please use [code=pascal][/code]-tags to avoid the forum software interpreting your code.

Sorry about that.  Fixed.


[0] Message Index

[#] Next page

Go to full version