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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listening and Sending on same Port

Status
Not open for further replies.

richrock316

Programmer
Jul 30, 2003
57
US
I am writing an app that takes a binary file and breaks it into "messages" (frtom a different app i wrote). These messages have a time stamp on them, the times between each message vary (could be 1/10 sec, 1/2 sec, etc.). I then make a connection across the network to another app that is listening. I send the first message, wait until the time between the 1st and 2nd message has passed (1/10 sec, etc.) and then send second message. This keeps going on until all messages are sent (appx 1/2 hour).

The server app (which somebody else is doing) receives the messages does some calculations and then sends them back as soon as the calculation is done. My side then receives the redone messages and stores them into a new file.

One of the requirements is that i only use 1 port for both sending and receiving.

The way i see it, it goes something like this.

1.pre-setup all messages
2.set port to send
3.send 1st message
4.set port to listen
5.if recalculated message received then store it, otherwise keep listening until right before time gap of 2nd message.
6.switch port back to send
7.send next message
8.repeat 4-7 until end of file

After all that rambling, what i really want to know is are there any pitfalls i should be aware of. Or are there any suggestions anybody could offer. Its the flipping back and forth on the same port that worries me.

This is the first time ive tried to tackle a client-server app, so i hope i was clear.

Thanks everybody
Richard
 
Once the connection is established you can send and receive on the same port (like a two way street), there is no need to break the connection.

You can use for eg:
Code:
Winsock1.SendData "Whatever your data is"

from either client or server

 
Thanks mememememe...

OK, So once the connection is made i just use SendData and whenever a DataArrival event comes in i use GetData. This just keeps going on back and forth. OK seems relatively easy.

Does winsock handle it, when you are sending data just as an incoming data arrives? In other words, does it put incoming "messages" in some kind of queue until the outgoing message is sent?

Richard

 
See the client server example for Winsock in help.
You have 1 winsock at each end
Configure 1 to listen (the server) on a fixed port number (say 1000)
Configure the other (the client) to Connect to the Server on this port.
The server replies with the Sub Winsock_RequestToSend()

Send each way with Winsock.Senddata Data

Receive each way on Sub Winsock_Dataarrival (Bytes)
and the Getdata statement like the example.

It is a good idea to close the connection when you are not using it and reopen it only when you need it otherwise if someone pulls out a cable for a minute without closing, it woont reconnect work when you plug it in without restarting the apps unless you have some fancy reconnection attempt routine on timer.
 
Thanks guys

Thats what im looking for. I guess i just convinced myself that this was going to be harder than it is.
Then again, im not finished yet, sdo we'll see how the rest ends up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top