当前位置: 技术问答>java相关
急急急!!socket通讯的问题!!(我会再加分的,i promise!!)
来源: 互联网 发布时间:2015-01-12
本文导语: 看了一些精华区的经验,但是我的socket现在还是不能顺利收发到数据 我用的是jb5,添加了tomcat3.2的Servlet,主要程序如下: import java.io.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public...
看了一些精华区的经验,但是我的socket现在还是不能顺利收发到数据
我用的是jb5,添加了tomcat3.2的Servlet,主要程序如下:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MonitorServlet extends HttpServlet implements SingleThreadModel {
...
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
...
String GWIP = request.getParameter("gwip");
String GWPort = request.getParameter("gwport");
//建立Socket,发给某网关自定义的http请求,并取回执行结果
String ReqToGW = "GET / status?password=bar HTTP/1.0";
Integer Port = new Integer(0);
Socket HttpPipe = new Socket(GWIP,Port.parseInt(GWPort));
InputStream inraw;
OutputStream outraw;
BufferedReader fromGW;
PrintWriter toGW;
inraw = HttpPipe.getInputStream();
outraw = HttpPipe.getOutputStream();
fromGW = new BufferedReader(new InputStreamReader(inraw));
toGW = new PrintWriter(new OutputStreamWriter(outraw));
toGW.flush();
toGW.println(ReqToGW);
int result = fromGW.read();
//现在程序到这里跑不动了,但是在GW能看到Socket connecting...接下来没有收到任何东东,为什么阿????
//根据收到的客户端Get请求参数和网关控制结果,组织返回客户端的html页面:
PrintWriter toClient = response.getWriter();
response.setContentType("text/html; charset=GBK");
toClient.println("
我用的是jb5,添加了tomcat3.2的Servlet,主要程序如下:
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MonitorServlet extends HttpServlet implements SingleThreadModel {
...
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
...
String GWIP = request.getParameter("gwip");
String GWPort = request.getParameter("gwport");
//建立Socket,发给某网关自定义的http请求,并取回执行结果
String ReqToGW = "GET / status?password=bar HTTP/1.0";
Integer Port = new Integer(0);
Socket HttpPipe = new Socket(GWIP,Port.parseInt(GWPort));
InputStream inraw;
OutputStream outraw;
BufferedReader fromGW;
PrintWriter toGW;
inraw = HttpPipe.getInputStream();
outraw = HttpPipe.getOutputStream();
fromGW = new BufferedReader(new InputStreamReader(inraw));
toGW = new PrintWriter(new OutputStreamWriter(outraw));
toGW.flush();
toGW.println(ReqToGW);
int result = fromGW.read();
//现在程序到这里跑不动了,但是在GW能看到Socket connecting...接下来没有收到任何东东,为什么阿????
//根据收到的客户端Get请求参数和网关控制结果,组织返回客户端的html页面:
PrintWriter toClient = response.getWriter();
response.setContentType("text/html; charset=GBK");
toClient.println("
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。