Yeah, I know the subject is vague, so I apologize :-)
I'm basically learning c# in my new job during the past month, and I'm feeling fairly comfortable with ASP.net, etc. I was given the task of making a basic socket listener that would basically listen on a specific port for data, and then write that data to a file. Eventually the data will be coming at any particular time, and won't be having any sort of header or footer or anything to handshake with. Pretty much anything that comes on that port we will be using, and right now I'd just like anything that comes on the port to be written to the file.
I found a sample project here:
http://www.codeproject.com/csharp/TCPServerAll.asp df=100&forumid=30826&exp=0&select=702231
that I based my stuff on. I ended up taking out the part that looks for a header to create the file name (I hard coded that for now) and tweaked it a little bit. What's happening though is that there is no "eof" being sent (because the data won't have that) and I think its not in turn closing the file once it opens it. I'm able to telnet to my service and send it data and it works, but if I exit without giving it the "eof" then it hangs and won't accept any more data until I stop and restart the service.
Can I modify this project to either close the file after every line write (that seems wasteful) or maybe I'm going about this all wrong Can anyone point me in a better direction Thanks!

C# socket programming help
Ruhina
Sorry for not helping you from my first post but i just realised that i didn't fully understand what your problem really was.
Some "telnet" application may send the data different..What i mean by different Well, for example, they may interpreter chars like UP ARROW and stuff like that.I'm not sure if your TCP server can handle special chars like this, and maybe it freezes when you try that.If you want, you can me send me your whole code at my mail, so i can have it a look and help you better this time! :)
Buffer is the default buffersize of WinSock.
ElmueSoft
What about buffer sizes Is there something where it can only have so much sent at one time I'm trying to look through my tutorial I based it on (mentioned above) to see if theres something in that. Any more ideas would be great! Thanks!
MarcusLCox
I'm still learning the ins and outs of the Socket class. I think right now the tutorial I based my project on has a timeout of 15 seconds or something before it kills the connection that was created if there was no activity. I've found where to change this as well. What I think is happening is that there is a command to "close" the file, and that's waiting for some data that never comes because that is not the nature of the data I will be receiving. The same goes for the filename: the data that will be sent is just going to be an occasional stream of data that I think eventually will be loaded into a database or something. Right now I'm just trying to append everything to a single text file to just get a dump of whats being read.
But my problem seems to be that the connection timesout because of inactivity, but the file hasn't been "closed", so then subsequent attempts to connect and open the file look to be failing. Maybe I'm off base with this completely. Would it be bad to open and close the file for each line that is read from the stream The nature of the data being read is that I won't have an "end of file" or some sort of code to look for to terminate the stream. Its just going to be random data every once in awhile. Thanks for all your help!!
Umeshpradhan
Nice move to start learning C#..You'll see that is very handy and easy going on many stuff.
About your project and question..You should set a timeout to the socket, or implement a ping command request at your service so you can check if the user is still alive or not.Setting timeout is very easy, it's a property exposed under the Socket class namespace.That's for the timeout part..To be sure it works ok, try testing your service from different IPs (and then check the threads opened by your connection requests).Also note that every connection should start its own thread as long as you don't want to be able to handle 1 connection per time.In addition note that you could implement of "file handling" in your service (i mean you don't have to hardcode it).The data could be something like this "Filename:Text to be written".You parse by IndexOf or Split (exposed under StringBuilder class/object) to get the Filename and Text to be written.
Let me know if you need anything else.
Giz.-