Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock - create a thread and assign a port number to it. 1

Status
Not open for further replies.

rakeshou

Programmer
Aug 15, 2006
17
US
Hello all,

I have a clientA program that connects to the server.

What i need is to create a thread in the clientA call it clientB which has a different port.

The clientA sends the IP address and Port number of the clientB to the server, and the server sends the Message "Hello" to the clientB and not ClientA.

First of all i dont know how to create a thread and how to assign a port to a thread.

Please help,

Its very urgent...

Thanks
 
hi,
I suggest to approach this problem with caution,
and resolve just one problem for time.

1) I belive the 2 sockets, need to speak on the same port.

2) What does mean "assign a port to a thread": the port
is a thing that has to do with sockets (TCPIP),
while you can make a thread of a process that moves a
ball on screen, without use network and TCPIP

3) First, resolve the task to task communication
(using sockets), without complicate it using thread.
Call it Martini program !

4) when two computer speaks togeter, perform a multi-thread
application that does not need sockets.
Call it Gin program !

5) when the second goes, mix them in a 3rd program.
Now you have made a perfect Martini Cocktail!

99) Drink it just at the end of job, and with moderation!

bye
 
assign a port to a thread"
do you mean, the thread is a static or global function, and it can not access the member of the class which not static, but the port is a member of the class and not static, Or the port was set by User?
Then,you know the static method declare is:
"DWORD WINAPI ThreadProc(LPVOID lpParameter);"
you can pass the port to lpParameter in CreateThread():
"HANDLE procHandle = CreateThread(NULL, 0, (LPThreadProc)myThreadProc, (LPVOID)&nPort, 0, NULL);"
and in the function ThreadProc, Convert lpParameter to unsigned long pointer, it point to the port.

If you want to access more than one of the member of class and not static, you can pass "this" to lpParameter:
"HANDLE procHandle = CreateThread(NULL, 0, (LPThreadProc)myThreadProc, (LPVOID)this, 0, NULL);"

 
the thread is created in the main function and and IP address of the Host and port number is passed to the thread.

I think I have to create an object of the struct sockaddr_in which will have the IP address of the Host and the port number too, and pass it to the thread.

Thanks for your reply BILL , it was helpful.

Rakesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top