Hi, I'm trying to write a client application for a server which I have no documentation of. The Communication is done over TCP/IP.
What I know of the server is:
It's on another machine on a LAN
It listens on port 4001
It Receives messages on port 4001
It sends messages to the client's TCP port 5001
------------------------------------------------------
The Client is supposed to send request messages and receive server replies.
Here's how I built the client:
Created one client socket and bound it to port 5001
Connected the socket to the server using the connect(...) function
from winsock2.h, using destination port 4001.
Run a while(1) loop which gets user input and calls the send(...)
function.
Run a thread which calls the recv(...) function, since the client
doesn't know when the server will send a message (sometimes it sends
messages to get the status of the client)
This all runs fine when testing it with a server app I built. The server app does the following:
Creates a Socket and binds it to port 4001
listens for a connection
after getting a connection request, it accepts the client and returns
a pointer to a socket. The server uses this pointer to send and
receive messages to the client.
With this setup, the client can send/recv as many messages, in any order, and it works fine.
The problem is that when testing against the proprietary server, I can send messages from the client, and the server tries to reply, but the replies do not reach the client's port. The server's log says (could not send message to client..., not sure what it means as I do not have the documentation), but using wireshark, I see the TCP data getting to the server, and the servers replies coming sometimes from port 4001 and sometimes from other ports like 3669.
There is a client application already built (it is proprietary so I need to build one myself), and it communicates well with the server.
I honestly don't know that is wrong with my client, as I understood, clients don't need to bind to a port, but I did it because I know for a fact the the server sends messages to that port (5001). Also, I am new with sockets, and what I get is:
client creates a socket (in my case, binds it to port 5001)
client connects to server
client can now send/recv messages
server creates socket
server binds socket to port 4001
server listens
server accepts and returns pointer to client socket
server uses pointer to send/recv messages
---------------------------------------------
Works with test applications, not with server.
can anyone help out?
The site warned me that my message was too long, and I apologize, I just want to give all the details. I will post code upon request.
Thanks in advance