-
August 11th, 2009, 12:19 AM
#1
How to send packet to myself when I'm disconnected
Hi
I'm programming in win32 for a Windows Mobile application. So this is the trouble I'm having. In my program, I would like to send a packet to my own phone without connecting to the internet.
If I'm connected to the internet, I could easily send a packet to myself through the connect(), send() and recv() function. But if I'm disconnected, the connect() function wouldn't work. Is there a way to send a packet to myself through another method?
I'm also not very familiar with the whole socket concept. Since the first parameter in the send() function is a "SOCKET s", do I need to declare a new socket beforehand? If so, what parameters should I put in this socket (so that I can be "connected" to myself)?
Thank you a lot.
Sheri
-
August 13th, 2009, 12:32 AM
#2
Re: How to send packet to myself when I'm disconnected
Not clear what your point here. If your socket is disconnected, you need to reconnect again
by calling connect() function but you don't need to re-declare socket variable.
henky
----------------------------------
henky@nok.co.id is not my email address anymore...
Jangan Pernah Menyerah
-
August 13th, 2009, 03:10 AM
#3
Re: How to send packet to myself when I'm disconnected
Actually, what I want to do is to send a packet with localhost IP address for already opened TCP connection. I don't want to use the connect() function because I don't want to open another TCP connection up. Additionally, I would like the recv() function to receive the packet that I sent through send().
I tried using sendto() function already, because I can specify the destination address (in this case, localhost). But for some reason, my recv() function still could not receive the packet. The following is part of the code I have:
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( TCP_PORT_NUM );
sendto(sid, msg_buffer, mData->length, 0, (SOCKADDR*) &clientService, sizeof(clientService));
sid is the name of the socket I declared earlier.
Any suggestions? Again, I want to send a packet to localhost IP address for already opened TCP connection.
Thanks.
Sheri
-
August 13th, 2009, 07:30 PM
#4
Re: How to send packet to myself when I'm disconnected
Originally Posted by shericn
Actually, what I want to do is to send a packet with localhost IP address for already opened TCP connection. I don't want to use the connect() function because I don't want to open another TCP connection up.
If that socket already connected, you can use that socket descriptor as receiver also. But you can't receive the packet which
is sent by the same socket (do you mean you connect the socket to the same socket ???)
HNK.
henky
----------------------------------
henky@nok.co.id is not my email address anymore...
Jangan Pernah Menyerah
-
August 14th, 2009, 04:17 PM
#5
Re: How to send packet to myself when I'm disconnected
Yes, I do want to send a packet to the same socket that as connected previously to another socket. So what you are saying is, this is not possible?
In that case, I would just try to do something else.
Thanks.
-Sheri
-
August 14th, 2009, 10:26 PM
#6
Re: How to send packet to myself when I'm disconnected
Originally Posted by shericn
Yes, I do want to send a packet to the same socket that as connected previously to another socket. So what you are saying is, this is not possible?
In that case, I would just try to do something else.
Thanks.
-Sheri
Ok, let me clear what you want to do.
You want to sending and receiving data in localhost without internet
connect, right?
If yes, I'd like you to understand that there is no difference concept
between localhost and internet for TCP/IP in sending/receiving.
You can test your receiving program whether it can receive or not by
using telnet. If your receiving proram can't receive (or in other case
it can't be connected), then there is something wrong with your
receiving program.
Also, socket programming concept is simple. One socket must work
as receiver and the other one must work as sender (peer-to-peer).
henky
----------------------------------
henky@nok.co.id is not my email address anymore...
Jangan Pernah Menyerah
-
August 18th, 2009, 08:06 AM
#7
Re: How to send packet to myself when I'm disconnected
I have no experience with mobile devices, but for a PC:
1) sendto() is to be used with UDP sockets, not TCP.
2) if you have a TCP socket which is not connected anymore, you can reconnect it to another socket - if i understand it right, you want to reconnect it to a new socket, which binds a local address. Of course this is possible, but you cannot reuse the old code in any way - treat the new connection as as a completely different "thing".
3) if you want to be able to receive data on 1 socket from 2 different sources at the same time, you must use UDP instead of TCP (and don't connect the socket).
Regards,
Cosmin
-
August 18th, 2009, 06:33 PM
#8
Re: How to send packet to myself when I'm disconnected
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|