Click to See Complete Forum and Search --> : RE: connecting to a socket


jom20
August 18th, 2003, 10:34 AM
hello,

i have some code that would create a socket, however when I try connecting it wouldn't work because I am not sure of the IP address. Does anyone have any idea of a method I could use to retrieve the IP address using Visual C++.

Thanks

Andreas Masur
August 18th, 2003, 10:51 AM
Take a look at this FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=233261)...

jom20
August 18th, 2003, 02:14 PM
Hi,

Thanks for your help. I have one problem though when I run it nothing appears.It seems like a stupid question but I am trying to figure out how I can print on the screen - just for checking purposes- the value of the IP address. For instance I know you can call MessageBox and then put a string inside but what if I wanted to print a value, how would I go about doing that?

Thanks

Andreas Masur
August 18th, 2003, 03:01 PM
Well...what screen? Do you have a GUI or a console application?

jom20
August 18th, 2003, 03:49 PM
hi,

I created a dialog based application. It has a form included and on this form at the moment I only have a button. When clicked then it should connect the socket.

The thing is I have connected a bluetooth chip to the computer (C1) and the chip is then connected using a serial cable to another computer (C2). Then C2 also has a bluetooth chip connecting it to C1.


C1 will be the client and C2 the server and so I was trying to create a socket and connect to the chip through it. I want to do this for both computer.


Thanks
Trisha

Andreas Masur
August 18th, 2003, 03:56 PM
Okay...since you do not have any output field (static text control) I would simply suggest to use a message box...thus (based on the FAQ)...

for(int iCnt = 0; ((pHost->h_addr_list[iCnt]) && (iCnt < 10)); ++iCnt)
{
memcpy(&SocketAddress.sin_addr, pHost->h_addr_list[iCnt], pHost->h_length);
strcpy(aszIPAddresses[iCnt], inet_ntoa(SocketAddress.sin_addr));
AfxMessageBox(aszIPAddresses[iCnt]);
}

This will open a message box for each IP address...

jom20
August 19th, 2003, 05:49 AM
Hi,


Thanks for that its just what I needed. I want to ask you one question however to clear things up. I connected -just for testing- one of the chip to one computer using a serial cable and then to the other computer using a USB cable. I have one computer set to listening on the port 4000 (just for testing) and the other computer should be trying to connect on port 4000. The thing is I am not sure if this is how I should be connecting both computers to the chip.


In other words if I merely create a socket on both computers and then set one to listen and the other to try and connect would the outcome be that they both connect to the chip and then can communicate to each other through the chip. At the moment that doesn't work, so I just want to check if I have to do anything else.


Thanks
Trisha

Andreas Masur
August 19th, 2003, 07:34 AM
Well...basically you are right. If you have two computers, one acts as the server (thus listening on port xxx) and the other one acts as the client (thus connecting to port xxx).

However, I do not know what these serial and USB connections are meant to be? Do you want communicate over a network or over serial?

jom20
August 19th, 2003, 07:44 AM
I want a connection over a serial cable(rs232) connected to the chip.

Andreas Masur
August 19th, 2003, 10:45 AM
Well...but this is different from network connections though...

jom20
August 19th, 2003, 11:21 AM
Its not a network, I just want to connect both computers using this chip. At the moment one of them creates a socket and listens whilst the other create a socket and tries to connect to the listening computer. The problem is that it doesn't connect. Its connecting to the chip.

Andreas Masur
August 19th, 2003, 04:13 PM
Well...I do not see how this would ever work. I do not know what the chip actually is supposed to do (and how it would do it), nevertheless...network connections are made through a network interface...and not through a serial cable...maybe I am missing something here...

jom20
August 20th, 2003, 04:55 AM
ummm I think that I might have been thinking wrong. Its not a network so it doesn't need that type of interface, however there are different layers to this chip and so I think what I need to do is to find a way to communicate with the layer which would allow me to connect both laptops.


Thanks for you help
Trisha

Andreas Masur
August 20th, 2003, 05:19 AM
Okay...I do not know the chip and what it does etc. However, you would rather need a serial connection between these components (PC1 - Chip - PC2) and then use serial communication instead...at least based on what you have described earlier...