Author Topic: Connection with another computer, winsock  (Read 6380 times)

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Connection with another computer, winsock
« Reply #15 on: December 03, 2014, 02:31:31 PM »
The good news is that your server code does work.
It receives what is sent to it - four bytes at a time, but it gets there.

It's actually your client code that's the problem.
Specifically, you're using a local variable in WndProc and assuming it will keep its value. It does not.

What this means is that the contents of 'buffer' (initialised earlier) will no longer be the same when you try to send it (it's in an entirely different invocation of WndProc!) So you're not sending 63, you're sending some random value.
As a quick fix, this will show that it works:

   lea esi,buffer
   mov DWORD PTR [esi],63
   invoke send,sock,esi,4,0


Overall, your code needs many fixes and could be tidied to make it much easier to read (and spot problems.)
Potato2

gelatine1

  • Member
  • **
  • Posts: 217
Re: Connection with another computer, winsock
« Reply #16 on: December 03, 2014, 09:13:18 PM »
Could you tell me how do you see that my server code is working ? i run my server in odbg and I put a breakpoint after the WM_SOCKET message (408). then I run the client (which connects to the server) but my server running in odbg never receives any WM_SOCKET message. So that gives me the feeling it is not working but clearly it did work for you ?
« Last Edit: December 04, 2014, 12:28:23 AM by gelatine1 »

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Connection with another computer, winsock
« Reply #17 on: December 04, 2014, 08:59:37 AM »
Load the server in the debugger, set a breakpoint on the call to accept, and another on recv, then run.
Now start your client and the debugger should hit the breakpoint for accept -- so the connection is being made.
Step over, or continue.
Then the recv breakpoint will be hit and you can see what bytes are actually received.
Potato2

gelatine1

  • Member
  • **
  • Posts: 217
Re: Connection with another computer, winsock
« Reply #18 on: December 05, 2014, 05:24:04 AM »
I did exactly as you said but the debugger did not hit the breakpoint for accept nor the breakpoint for recv like you said. Is something wrong or weird going on with my computer that doesn't happen for your computer ? Anyone knows what's going wrong maybe ?

gelatine1

  • Member
  • **
  • Posts: 217
Re: Connection with another computer, winsock
« Reply #19 on: December 05, 2014, 06:54:56 PM »
Okay, I tried to test using the "telnet 127.0.0.1" command and then I finally had an incoming connection in my server.. :D Then I used the "sen abcd" and I also received a FD_READ message and I received " nes" so a little unexpected but it works :p
Still I am bugged why I can't make a connection between my client and my server.. :/ anyone who can help ?

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Connection with another computer, winsock
« Reply #20 on: December 05, 2014, 11:33:27 PM »
Check windows' firewall isn't blocking connections;
check anti-virus isn't blocking anything;
try using a lower port number (between 1024 and 5000).


You received " nes" because you sent the bytes 's','e','n',' ','a','b','c','d' and then extracted the first four as a dword (dwords are stored 'backwards,') if you took the next four it would be "dcba".
Potato2