Client's connecting to nothing apparently
When I run my client without running the server, the client appears to connect to something. I''m using an abstract port number (54321), which isn''t already being used as far as I know. When I run netstat -a (under Win2k) I don''t see this new "connection".
I''m getting back a valid socket, which is even more confusing. If I change the port number it anything else, it still connects to "nothing".
What the heck is going on? Any ideas or suggestions are greatly appreciated!!
Thanks
---------------------http://www.stodge.net
I was just sorting that out when I realised that the connection is marked as pending, not connected. I''m using HawkNL, and the library returns TRUE when you call connect even if the connection isn''t established. You only know that the connection has been fully established when you try to read from the socket. This seems a little odd to me. It''s really making my code a mess.
This absolutely sucks.
Thanks anyway.
if (nlConnect() == NL_TRUE){ // connection established. NOT REALLY! nlRead(); if (nlGetError() == NL_CON_REFUSED) { printf"Hard luck, your connection wasn''t really established\n"); }}
This absolutely sucks.
Thanks anyway.
---------------------http://www.stodge.net
quote:
Original post by stodge
I was just sorting that out when I realised that the connection is marked as pending, not connected. I''m using HawkNL, and the library returns TRUE when you call connect even if the connection isn''t established. You only know that the connection has been fully established when you try to read from the socket. This seems a little odd to me. It''s really making my code a mess.if (nlConnect() == NL_TRUE){ // connection established. NOT REALLY! nlRead(); if (nlGetError() == NL_CON_REFUSED) { printf"Hard luck, your connection wasn''t really established\n"); }}
THis is probably because connections and data transfer are asynchronous ? You call nlConnect() and all it does it put the connect into a buffer, and a separate thread connects. You should wait for the connected event before using the socket. Is there a blocking variant of the connect ?
October 10, 2002 05:49 PM
Even if it''s not actually asynch, even in winsock if you connect() on a non-blocking socket, it will return immediately and you don''t find out if it ever connected until you try to recv or send to it (or check if the socket is readable/exceptionable with select() )
@Anonymous: I didn''t realise that.
@Fidelio_: I think there is a blocking variant. I don''t want it to block as that will pause the program for a second at the very least, and that''s a freeze that I don''t want.
Thanks
@Fidelio_: I think there is a blocking variant. I don''t want it to block as that will pause the program for a second at the very least, and that''s a freeze that I don''t want.
Thanks
---------------------http://www.stodge.net
This is quite a common problem with people new to networking.
You want a connection but you don''t want your application to stop while the connection is being made. What can you do then? The call can''t return NULL idication a failure so it indicates a pending connection and passes you back a pointer or reference. You then have to check later on, or wait for a message or event, that tells you if the connection really happened or failed.
This kind of thing is common for things which could take a long amount of time and is known as a factory is some cases.
You want a connection but you don''t want your application to stop while the connection is being made. What can you do then? The call can''t return NULL idication a failure so it indicates a pending connection and passes you back a pointer or reference. You then have to check later on, or wait for a message or event, that tells you if the connection really happened or failed.
This kind of thing is common for things which could take a long amount of time and is known as a factory is some cases.
Martin Piper
I can live with this; it seems logical. I can''t live with the fact that HawkNL tells me the connection was established when in fact it''s still pending.
Thanks
Thanks
quote:
Original post by fnagaton
This is quite a common problem with people new to networking.
You want a connection but you don''t want your application to stop while the connection is being made. What can you do then? The call can''t return NULL idication a failure so it indicates a pending connection and passes you back a pointer or reference. You then have to check later on, or wait for a message or event, that tells you if the connection really happened or failed.
This kind of thing is common for things which could take a long amount of time and is known as a factory is some cases.
---------------------http://www.stodge.net
quote:
Original post by stodge
You only know that the connection has been fully established when you try to read from the socket. This seems a little odd to me. It's really making my code a mess.
It doesn't have to be. One of the examples (getfile.c) shows you a nice way of doing this.
while(nlWrite(sock, (NLvoid *)buffer, (NLint)strlen(buffer)) < 0){ if(nlGetError() == NL_CON_PENDING) { nlThreadYield(); continue; } close(f); printErrorExit();}
I would imagine you can use something very similar to check if your connection is really valid.I'm having funny problems compiling anything with HawkNL when I link to the NLstatic.lib library. Everything works fine when I use HawkNL.lib, but I'd rather not have an additional DLL file. It just doesn't link properly. Perhaps I have to compile the lib myself (as opposed to using precompiled ones), since I'm using VS.NET 2003 (7.1).
Edit: Never mind, got it. All I had to do was link to the Winsock lib and clear up some default library confusion.
"/NODEFAULTLIB:LIBCD NLstatic.lib WS2_32.lib"
---
shurcooL`
[edited by - shurcooL on January 19, 2004 5:55:08 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement