473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

reusing sockets

12
Hello,

I've a quite simple question about socket programming (but I can't find the answer in widely available sources). Is it possible to 'reuse' a socket within 1 connection? In other words, is it possible to place 'send()' and 'recv()' in a loop in the code below? In that case time will be saved because the socket doesn't have to be opened and closed for every new buffer. The socket desciptor stays the same, the only thing that has to be changed is the message buffer.

socket();
connect();
send(); //instead, while(1) {buffer = "new buffer"; send(buffer); recv();}
recv(); // "
close();

Thanks!
Feb 18 '08 #1
5 5520
gpraghuram
1,275 Expert 1GB
Hello,

I've a quite simple question about socket programming (but I can't find the answer in widely available sources). Is it possible to 'reuse' a socket within 1 connection? In other words, is it possible to place 'send()' and 'recv()' in a loop in the code below? In that case time will be saved because the socket doesn't have to be opened and closed for every new buffer. The socket desciptor stays the same, the only thing that has to be changed is the message buffer.

socket();
connect();
send(); //instead, while(1) {buffer = "new buffer"; send(buffer); recv();}
recv(); // "
close();

Thanks!
I recommend you to read a good Socket programming tutorial to understand this.
While sending message we dont create a socket newly every time , we change only the message buffer

Raghuram
Feb 18 '08 #2
Omega
12
Okay, but then you send a larger message in parts and after that you receive a message in parts. But what I want is to send a small message, receive an answer and then send a new message, receive an answer etc. I tried this but it doesn't work for me. I seems that the server closes that particular socket connection after 1 reply.
Feb 18 '08 #3
Okay, but then you send a larger message in parts and after that you receive a message in parts. But what I want is to send a small message, receive an answer and then send a new message, receive an answer etc. I tried this but it doesn't work for me. I seems that the server closes that particular socket connection after 1 reply.
No , Never server closes the socket , until unless you call "close()". I think there is something else gone wrong.I could help you if send me the source code.
-Arul
Feb 18 '08 #4
Omega
12
No , Never server closes the socket , until unless you call "close()". I think there is something else gone wrong.I could help you if send me the source code.
-Arul
Thanks for your offer, but it is not necessary to fix the code. I only need to mention this issue as a recommendation in a report. Therefore I needed a confirmation that this can indeed improve the written software (it already works, but quite slow). Thanks!
Feb 18 '08 #5
gpraghuram
1,275 Expert 1GB
Thanks for your offer, but it is not necessary to fix the code. I only need to mention this issue as a recommendation in a report. Therefore I needed a confirmation that this can indeed improve the written software (it already works, but quite slow). Thanks!


Check the server side code. what it does after sending the message to the client.
Check whether any shutdown/close call in the server side and analyze the logic there

Raghuram
Feb 19 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jo Voordeckers | last post by:
Hello all, I'm pretty new to the Java newsgroups so I apologize for dropping this into several maybe offtopic groups. I'm sorry! So on to my problem... I've come to a point in our RMI...
2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
9
by: Alan | last post by:
Using VC++ (1998) compiler with PFE32 editor in Win2K Pro SP4. (DigitalMars CD on order. ) The program (below) instantiates a class and then deletes it. I would have thought that reusing the...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
3
by: J C | last post by:
Hi, I'm using UDPClient to make a simple DNS server. I notice that intermittently and unpredictibly I get: Unhandled Exception: System.Net.Sockets.SocketException: An existing connection...
7
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the output.. ../../../sockets.cpp: In constructor...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.