473,569 Members | 2,698 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending and receiving data using networkstream

1 New Member
I wrote a class to connect to a server using tcpclient.
I need to connect to the server and the connection must be open.Then i need to send request to the server again and again.But the problem is that i can communicate with the servet just for one time,the first time i connect to the server,send data and receive response,but when i want to receive data for another time,there won't be any response.some body help me please,whats the problem???
this is the class code i wrote:
----------------------------------------------------------------------

public class TCPAgent
{

TcpClient TCPconn = new TcpClient();
NetworkStream NetWorkStream;
public void Connect(string Server , int port)
{
TCPconn.Connect (Server, port);
NetWorkStream = TCPconn.GetStre am();

}

public string transfer(string SendCommand)
{
byte[] SendCmd = Encoding.ASCII. GetBytes(SendCo mmand);
NetWorkStream.W rite(SendCmd,0, SendCmd.Length) ;
StreamReader objSR = new StreamReader(TC Pconn.GetStream (), Encoding.ASCII) ;
return (objSR.ReadToEn d());
}
public string close
{
set
{
this.NetWorkStr eam.Close();
this.TCPconn.Cl ose();
}


}



}
May 6 '06 #1
1 3342
Banfa
9,065 Recognized Expert Moderator Expert
OK I am guessing here but I think it might be worth finding out what the server is doing. I think it may be possible that having handled a request the server is then closing the connection so that no more requests work. I think that you have to tell the server, somehow, to keep your connection live until you say otherwise.
May 8 '06 #2

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

Similar topics

0
2406
by: midnighthell | last post by:
I'm using MemoryStream, and when I send this stream over the network with TCP using NetworkStream , I must Deserialize it, but I don't how to convert from NetworkStream to MemoryStream, I have tried something like that, but it don't work: System.Net.Sockets.NetworkStream netstream =TCPClient.GetStream(); MemoryStream memStrim=new...
10
12179
by: Jim H | last post by:
I have a UDP socket that sends out a request on a multicast socket and waits for a response. This client is not listening on a multicast IP but the local IP. The server (UNIX) responds to the sender's IP. Using debug files on the server I see the server receive the request from my application on my machine and I see the server send to the...
1
1090
by: Mike | last post by:
Hi, We are in the process of evaluating a system that would allow us to receive data from third-parties and send data to partner companies. Our infrastructure includes Microsoft Navision, a SQL Server, and .NET 2.0. My idea would be to use web services with XML to fullfil the above requirements, but I have very little experience on web...
1
2868
by: fabrizio.viggiani | last post by:
I need to send a mail message to an SMTP server. The .net framework provides System.Net.Mail namespace to send an email: - Build a System.Net.Mail.MailMessage and send it using SmtpClient The message that I have to send is already in the form of a MIME stream (multipart, attachments and digitally signed), so using the classes of the...
5
5507
by: jaco.versfeld | last post by:
Hi There, I have a basic TCP client and TCP server in C++. The TCP client connects to the server, and after a setup phase starts to transmit a file to the TCP server using multiple packets (fixed amount of bytes, except for the last packet). This is accomplished by using a for loop and the "int send(socket, buffer, bufferlength, 0)"...
1
15048
by: Rich | last post by:
Hello, I am working on a python library for sending and receiving data from a Subaru's ECU (the fuel injection computer) via the OBD-II port and an OBD to USB cable, with the Subaru Select Monitor protocol. There are a few open source programs that do this already (http://romraider.com/ , http://jdash.sourceforge.net/ ,...
3
4430
by: dtittle | last post by:
Hi, I am working on a C# app for a mobile 05 device that will send data to a server. I think I need to use the NetWorkStream to send it via TCP but I'm not sure how to do that. The book that I am using is not very clear on that subject. Can anyone help? Thanks,
1
3356
Airslash
by: Airslash | last post by:
Hello, The problem is that my server is not receiving data. The code below are the various classes I designed around sockets. It will be big... I have run the code with the debugger, and I see in the debug output that the client connects to the server, the events get fired and the disconnect event gets fired as well. I get confirmation...
1
1529
by: kishoreforqns | last post by:
how to download files (2mb>) using networkstream from a mailserver.. i can conenct to the mail server, list unread mails, and i can also retreive unread mails. but that till 1.5 mb. how to do this.. what concept i have to use.. how the server is sending the data.. now i am using the code given for retreive (RETR) Thread.Sleep(100000); ...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.