hadoop Problem binding to :9000 : Address already in use

命令: lsof -i:9000  
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

java    9302  root       37u  IPv6  39077      0t0  TCP hhumaster:cslistener(LISTEN)

kill 9302

展开阅读全文

java.net.BindException: Address already in use

03-02

java.net.BindException: Address already in usern at java.net.PlainDatagramSocketImpl.bind0(Native Method)rn at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)rn at java.net.DatagramSocket.bind(DatagramSocket.java:368)rn at java.net.DatagramSocket.(DatagramSocket.java:210)rn at java.net.DatagramSocket.(DatagramSocket.java:261)rn at java.net.DatagramSocket.(DatagramSocket.java:234)rn at com.vino.tools.UDPSocket.(UDPSocket.java:33)rn at com.vino.tools.UdpClient.sendData(UdpClient.java:86)rn at com.vino.tools.UdpClient.udpUpdate(UdpClient.java:61)rn at com.vino.components.terminal.action.UDPUpgradeAreaAction.execute(UDPUpgradeAreaAction.java:75)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:585)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)rn at com.vino.frame.VinoIntercept.intercept(VinoIntercept.java:31)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn怎么解决,为什么在没有发布之前可以发布之后就报错???? 论坛

求助:Address already in use: connect???

08-07

2007-08-07 08:47:17 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionrnorg.apache.jasper.JasperException: Unable to connect to any hosts due to exception: java.net.BindException: Address already in use: connectrnrn** BEGIN NESTED EXCEPTION ** rnrnjava.net.BindExceptionrnMESSAGE: Address already in use: connectrnrnSTACKTRACE:rnrnjava.net.BindException: Address already in use: connectrn at java.net.PlainSocketImpl.socketConnect(Native Method)rn at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)rn at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)rn at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)rn at java.net.Socket.connect(Socket.java:426)rn at java.net.Socket.connect(Socket.java:376)rn at java.net.Socket.(Socket.java:291)rn at java.net.Socket.(Socket.java:119)rn at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)rn at com.mysql.jdbc.MysqlIO.(MysqlIO.java:225)rn at com.mysql.jdbc.Connection.createNewIO(Connection.java:1783)rn at com.mysql.jdbc.Connection.(Connection.java:450)rn at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)rn at java.sql.DriverManager.getConnection(DriverManager.java:512)rn at java.sql.DriverManager.getConnection(DriverManager.java:193)rn at org.apache.jsp.dw_xxzw_jsp._jspService(dw_xxzw_jsp.java:82)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)rn at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)rn at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)rn at java.lang.Thread.run(Thread.java:536)rnrnrn** END NESTED EXCEPTION **rnrn -----------------------------------------------------------------------------------------------------rnrn是什么问题啊?怎么解决?rnrn谢谢rn 论坛

socket编程报Address already in use

07-07

我服务器监听8989端口,,然后我启用了两个客户端来连接,,,但是第一个能连接,第二个客户端就会报java.net.BindException: Address already in use: JVM_Bind异常。。。。。但是我看极客学院里的视频也是一个端口给多个客户端连接的啊。。。。请问这是为什么呢???rnrn服务器端rn[code=java]public class ServersL extends Thread rn public static void main(String[] args) rn new ServersL().start();rnrn rnrn rnrn @Overridern public void run() rn try rn jf.jt.append("服务器已启动!\n");rn while (true) rn @SuppressWarnings("resource")rn ServerSocket ss = new ServerSocket(8989);rn Socket s = ss.accept();rn // 只允许最多两个连接rn if (SocketManger.getSocketManger().socketList.size() < 2) rn // 建立了连接rn JOptionPane.showMessageDialog(null, "有客户连接到本服务器8989");rn ChessSocket cs = new ChessSocket(s);rn cs.start();rn SocketManger.getSocketManger().add(cs);rn else rn JOptionPane.showMessageDialog(null, "该服务里已满!");rn rn rn sleep(1000);rnrn // 将socket给新的线程rn // ne=new ChessSocket(s);rn // ne.start();rn // new newScoket(s).start();rn rn catch (Exception e) rn e.printStackTrace();rn rn rnrnrnrnpublic class SocketManger rn private SocketManger()rn rn rn private static final SocketManger insterce=new SocketManger();rn public static SocketManger getSocketManger() rn return insterce;rn rn Vector socketList=new Vector<>();rn public void add(ChessSocket e) rn socketList.add(e);rn rn public void publish(ChessSocket me,String out) rn for (int i = 0; i < socketList.size(); i++) rn ChessSocket ch=socketList.get(i);rn if (!me.equals(ch)) rn ch.out(out);rn rn rn rnrnrnpublic class ChessSocket extends Thread rnSocket socket;rnrn public ChessSocket(Socket s) rn this.socket = s;rn rn public void run() rn rnrn[/code]rnrn客户端rn[code=java]public class MySocket rn rn public static void main(String[] args) rn try rn show jf=new show();rn Socket s=new Socket("127.0.0.1", 8989);rn catch (UnknownHostException e) rn e.printStackTrace();rn catch (IOException e) rn e.printStackTrace();rn rn rnrn[/code]rnrn我省略了部分与这个错误无关的代码 论坛

Tomcat6.0...java.net.BindException: Address already in use: JVM_Bind

08-28

2010-8-28 20:56:12 org.apache.catalina.core.AprLifecycleListener initrn信息: The Apache Tomcat Native library which allows optimal performance in production environments rnrnwas not found on the java.library.path: C:\Program Files\MyEclipse 6.0\bin;C:\Program Files\Apache rnrnSoftware Foundation\Tomcat 6.0\binrn2010-8-28 20:56:13 org.apache.coyote.http11.Http11Protocol initrn信息: Initializing Coyote HTTP/1.1 on http-8888rn2010-8-28 20:56:13 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 1250 msrn2010-8-28 20:56:13 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2010-8-28 20:56:13 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.10rn2010-8-28 20:56:18 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\cxf-demo001rnrn\WEB-INF\lib\geronimo-servlet_2.5_spec-1.2.jar) - jar not loaded. See Servlet Spec 2.3, section rnrn9.7.2. Offending class: javax/servlet/Servlet.classrn2010-8-28 20:56:23 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\cxf-rnrndemo001.myeclipse.bak\WEB-INF\lib\geronimo-servlet_2.5_spec-1.2.jar) - jar not loaded. See Servlet rnrnSpec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.classrn2010-8-28 20:56:25 org.apache.coyote.http11.Http11Protocol startrn信息: Starting Coyote HTTP/1.1 on http-8888rn2010-8-28 20:56:25 org.apache.jk.common.ChannelSocket initrn信息: Port busy 8009 java.net.BindException: Address already in use: JVM_Bindrn2010-8-28 20:56:25 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8010rn2010-8-28 20:56:25 org.apache.jk.server.JkMain startrn信息: Jk running ID=1 time=0/109 config=nullrn2010-8-28 20:56:25 org.apache.catalina.startup.Catalina startrn信息: Server startup in 12391 msrn2010-8-28 20:56:25 org.apache.catalina.core.StandardServer awaitrn严重: StandardServer.await: create[8005]: rnjava.net.BindException: Address already in use: JVM_Bindrn at java.net.PlainSocketImpl.socketBind(Native Method)rn at java.net.PlainSocketImpl.bind(Unknown Source)rn at java.net.ServerSocket.bind(Unknown Source)rn at java.net.ServerSocket.(Unknown Source)rn at org.apache.catalina.core.StandardServer.await(StandardServer.java:373)rn at org.apache.catalina.startup.Catalina.await(Catalina.java:616)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:576)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rnrnrn之前说8080端口被占用,我用netstat -a查了一下rnProto Local Address Foreign Address StaternTCP user:8080 user:0 LISTENINGrn我也不知道这什么意思谁占了,没办法我把server.xml里的端口改成8888,又有端口被占用rnrn第一次用tomcat,请尽量说详细点,谢谢了 论坛

莫名其妙:Address already in use:connect

01-22

初学java,在一个线程中实现一个Socket客户端,向server发送命令包,并取回。由于协议规定每次发送数据包后都须重新连接,所以在run()中一个循环中写:rn //以下语句处于一个循环中,其中serverIP和serverPort是类的数据成员。rn try rn //建立Socket Client rn client = new Socket(InetAddress.getByName(serverIP),serverPort);rn in =rn new BufferedReader(rn new InputStreamReader(rn client.getInputStream()));rn out =rn new PrintWriter(rn new BufferedWriter(rn new OutputStreamWriter(rn client.getOutputStream())));rn //向服务器发包rn out.write("...");rn out.flush();rn //收包rn ...(in.readLine());rn //释放CPUrn try rn sleep(100);rn catch (Exception e) rn ...rn rn catch (IOException e) rn ...rnrn finally rn try rn //关闭Socket,关闭流rn client.close();rn in.close();rn out.close();rn catch (IOException e) rn ...rn rn //进入下一次循环rn问题:rn 1、此段代码能都正常运行,但执行一段时间后出现:Address alread in use:connect异常!而且出现时间并不固定:( 。rn 2、其实InetAddress.getByName(serverIP)会有可能引发一个UnknowHost的异常,java为什么没有强制我处理或者throws出来呢?难道编译器看到有catch就不管了?rn 3、为了满足协议中每次重连的要求,socket和输入输出流每次都要重新new,很浪费资源阿,有没有什么好办法?rnrn请多多执教,先写过了。 论坛

java.net.BindException: Address already in use: bind

02-21

flex初学者 用Myeclipse8.5+flash builder 4.6 + blazeds.warrn我新建了个flex项目 部署在tomcat6.0上 启动服务器报了一下错误:rn2012-2-21 14:50:21 org.apache.catalina.core.AprLifecycleListener initrn信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_16\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\binrn2012-2-21 14:50:21 org.apache.coyote.http11.Http11Protocol initrn信息: Initializing Coyote HTTP/1.1 on http-8089rn2012-2-21 14:50:21 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 353 msrn2012-2-21 14:50:21 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2012-2-21 14:50:21 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.20rn2012-2-21 14:50:22 org.apache.catalina.startup.HostConfig deployWARrn信息: Deploying web application archive blazeds.warrn2012-2-21 14:50:23 org.apache.catalina.startup.HostConfig deployWARrn信息: Deploying web application archive ds-console.warrn2012-2-21 14:50:24 org.apache.catalina.startup.HostConfig deployWARrn信息: Deploying web application archive flex.warrn02/21 14:50:26 INFO Loading configuration file C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\flex\WEB-INF\flex\flex-webtier-config.xmlrn02/21 14:50:26 INFO Loading configuration file C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\flex\WEB-INF\flex\flex-config.xmlrn2012-2-21 14:50:26 org.apache.catalina.core.ApplicationContext logrn信息: FlexMxmlServlet: Starting Adobe Flex Web Tier Compilerrn2012-2-21 14:50:26 org.apache.catalina.core.ApplicationContext logrn信息: FlexMxmlServlet: Adobe Flex Web Tier Compiler Build: 173666rn2012-2-21 14:50:26 org.apache.catalina.startup.HostConfig deployWARrn信息: Deploying web application archive samples.warrn02/21 14:50:29 INFO Loading configuration file C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\samples\WEB-INF\flex\flex-webtier-config.xmlrn02/21 14:50:30 INFO Loading configuration file C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\samples\WEB-INF\flex\flex-config.xmlrn2012-2-21 14:50:30 org.apache.catalina.core.ApplicationContext logrn信息: FlexMxmlServlet: Starting Adobe Flex Web Tier Compilerrn2012-2-21 14:50:30 org.apache.catalina.core.ApplicationContext logrn信息: FlexMxmlServlet: Adobe Flex Web Tier Compiler Build: 155539rn2012-2-21 14:50:30 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\bin\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.classrn[Flex] RTMP-Server on port: 2038 failed to start up.rnjava.net.BindException: Address already in use: bindrn at sun.nio.ch.Net.bind(Native Method)rn at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)rn at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)rn at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52)rn at flex.messaging.endpoints.rtmp.BaseNIORTMPServer.run(BaseNIORTMPServer.java:155)rn at java.lang.Thread.run(Thread.java:619)rnrn2012-2-21 14:50:32 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\FlexJava\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.classrn2012-2-21 14:50:34 org.apache.coyote.http11.Http11Protocol startrn信息: Starting Coyote HTTP/1.1 on http-8089rn2012-2-21 14:50:34 org.apache.jk.common.ChannelSocket initrn信息: JK: ajp13 listening on /0.0.0.0:8009rn2012-2-21 14:50:34 org.apache.jk.server.JkMain startrn信息: Jk running ID=0 time=0/31 config=nullrn2012-2-21 14:50:34 org.apache.catalina.startup.Catalina startrn信息: Server startup in 12191 ms 论坛

tomcat 错误提示Address already in use

03-13

用 java、tomcat5.5、SQL Server2000建立了一个应用。其中数据库连接方式采用的是tomcat连接池的方法。rn但是最近一两天,访问系统总是提示 Error Create Sockets 错误,查tomcat日志有如下提示:rn请问大家是怎么回事,怎么处理?rnrn2009-3-13 17:08:02 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet jsp threw exceptionrnjava.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Address already in use: connectrn at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)rn at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)rn at com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)rn at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)rn at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)rn at com.microsoft.jdbc.base.BaseStatement.(Unknown Source)rn at com.microsoft.jdbc.base.BaseConnection.createStatement(Unknown Source)rn at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.createStatement(DelegatingConnection.java:173)rn at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.createStatement(PoolingDataSource.java:209)rn at org.apache.jsp.index_jsp._jspService(index_jsp.java:265)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)rn at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)rn at java.lang.Thread.run(Unknown Source)rn 论坛

udp 出现address already in use

04-11

我就是模仿unix网络编程上写了一个很简单的时间服务器的例子,用udp实现,如果有udp请求就发送当前时间给客户,可是运行一次成功后,关掉进程,入过在运行的话出现address already in usern关掉进程等了很长时间还是这样,[code=C/C++]rn# include "unp.h"rnint udp_server(const char *host,const char *serv,socklen_t *addrlenp)rnrn int sockfd,n;rn struct addrinfo hints,*res,*ressave;rn bzero(&hints,sizeof(hints));rn hints.ai_socktype=SOCK_DGRAM;rn hints.ai_flags=AF_UNSPEC;rn hints.ai_flags=AI_PASSIVE;rn if((n=getaddrinfo(host,serv,&hints,&res))!=0)rn rn err_quit("get addrinfo error %s",gai_strerror(n));rn rn ressave=res;rn dorn rn if((sockfd=socket(res->ai_family,res->ai_socktype,res->ai_protocol))<0)rn continue;rn if(bind(sockfd,res->ai_addr,res->ai_addrlen)<0)rn rn printf("bind %s error \n",sock_ntop(res->ai_addr,res->ai_addrlen));rn close(sockfd);rn continue;rn rn elsern break;rn while(res=res->ai_next);rn if(NULL==res)rn rn printf("udp_server error\n");rn return -1;rn rn if(addrlenp)rn *addrlenp=res->ai_addrlen;rn freeaddrinfo(ressave);rn return sockfd;rnrnint main(int argc,char **argv)rnrn int sockfd,n;rn time_t ticks;rn socklen_t len;rn char sendline[MAXLINE];rn SIN cliaddr;rn /*char *host[100];rn char *servlen[100];rn SIN addr;*/rn if(argc!=3)rn err_quit("usage client host service");rn if((sockfd=udp_server(argv[1],argv[2],&len))<0)rn err_sys("udp_server error\n");rn /*len=sizeof(addr);rn getsockname(sockfd,(SA *)&addr,&len);rn printf("%s\n",sock_ntop((SA*)&addr,len));*/rnrn while(1)rn rn len=sizeof(SA);rn recvfrom(sockfd,sendline,MAXLINE,0,(SA *)&cliaddr,&len);rn ticks=time(NULL);rn snprintf(sendline,MAXLINE,"%s\n",ctime(&ticks));rn sendto(sockfd,sendline,strlen(sendline),0,(SA*)&cliaddr,len);rn rnrn return 0;rnrnrnrnrn[/code] 论坛

没有更多推荐了,返回首页