473,548 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket Hang Problem (Weird)

Hello!
I have a J# socket client that does an HTTP Post. Code pasted below. This
client works fine on my XP and Win 2003 boxes, but on my Win 2000 Server box,
the socket just hangs when it tries to read. No exception nothing just hangs.
Any suggestion?

public static String httpPost(String url, String payload, String
ContentType)thr ows Exception, System.Exceptio n
{
WebResponse result = null;
StreamReader sr = null;

try
{
WebRequest req = WebRequest.Crea te(url);
req.set_Method( "POST");
//req.set_Content Type("applicati on/x-www-form-urlencoded");
req.set_Content Type(ContentTyp e);

ubyte[] SomeBytes = null;

if (payload != null)
{

//SomeBytes = HttpUtility.Url EncodeToBytes(p ayload);
SomeBytes = Encoding.get_UT F8().GetBytes(p ayload);
req.set_Content Length(SomeByte s.length);
Stream newStream = req.GetRequestS tream();
newStream.Write (SomeBytes, 0, SomeBytes.lengt h);

newStream.Close ();
}
else
{
req.set_Content Length(0);
}

result = req.GetResponse ();
Stream ReceiveStream = result.GetRespo nseStream();
Encoding encode = System.Text.Enc oding.GetEncodi ng("utf-8");
sr = new StreamReader(Re ceiveStream, encode);
System.Text.Str ingBuilder strb = new StringBuilder() ;
String str;
while ((str = sr.ReadLine()) != null)
{
strb.Append(str ).Append( "\r\n");
}
return System.Web.Http Utility.UrlDeco de(strb.ToStrin g(), encode);
}
catch(Exception e)
{
throw e;
}
catch (System.Excepti on se)
{
throw se;
}
finally
{
if(sr != null)
sr.Close();

if (result != null)
result.Close();
}
}//getPage
Jul 21 '05 #1
0 1291

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
8494
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for my server program written in python it simply hangs.it does not show any error also.I've tried sample programs available .I don understand what...
1
1555
by: Koen Vossen | last post by:
Hi, I came across some exceptional behaviour (pun intended) when I was programming a small chat server. I've simplified my original code to the following minimal version that still exhibits the same problem: <code> #!/usr/bin/env python import socket
1
3799
by: martinnitram | last post by:
Dear all, following are some piece of my code (mainly create a socket connection to server and loop to receive data): # function to create and return socket def connect(): server_config = ('192.168.1.50', 3333); sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect()
1
2968
by: Dave | last post by:
Hi, i am writing a c# application that use direct show to play mpg file but when i declere a socket in my c# application i just cant play the file enymore, It seems that the problem is because we are tring to write this lines: IPAddress ipAddress = Dns.Resolve("localhost").AddressList; TcpListener tcpServerListener = new...
2
3629
by: zb011 message | last post by:
Hi all, I have coded an outbound Socket program in C on a solaris box that sends out data and receives an acknowledgement for it. However, have faced this problem of a "HANG" state, whereby the read() function does not return any values. ===========code attached============================= int readn(int fd, char *ptr) {
2
1153
by: Lespaul36 | last post by:
I have tried many things. I still have not found anything that seems to work. Here is the portions of my code that deal with the listening socket maybe you have a better idea? The form still seems to hang. I got it to not hang if I used a loop with a application.doevents, but it was not CPU friendly. I had a suggestiong using channels,...
0
277
by: Tejaswi | last post by:
Hello! I have a J# socket client that does an HTTP Post. Code pasted below. This client works fine on my XP and Win 2003 boxes, but on my Win 2000 Server box, the socket just hangs when it tries to read. No exception nothing just hangs. Any suggestion? public static String httpPost(String url, String payload, String ContentType)throws...
0
4246
by: chsalvia | last post by:
On Linux (Ubuntu) I'm trying to figure out how to avoid recv() calls that hang forever by using using a non-blocking socket along with the select() function. This seems to be the standard way to avoid recv() calls that hang forever. I'm having difficulty getting this to work however. It seems to work sometimes, but occasionally the recv()...
3
3607
by: Joe Blauth | last post by:
Hi all, I am currently working on a small application that sends messages from a client to a server and receives messages in return. Basically the functionality is made with sockets which is working just fine except of one little thing. whenever the client tries to receive a message the server has sent it goes into a hang. unfortunately...
0
7518
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
7444
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
7711
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
7954
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
7805
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...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5085
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...
1
1932
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
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.