`
liomao
  • 浏览: 78649 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Something about Socket

阅读更多

Java很强大,socket 通信几句就搞定。

服务端和客户端(最差的代码):

import java.net.*;
import java.io.*;

class ser
{
	public static void main(String[] aa)
	{
		try{
		ServerSocket sr=new ServerSocket(3000);
		Socket s=sr.accept();
		DataOutputStream o=new DataOutputStream(s.getOutputStream());
		o.writeUTF("test Socket~~~~~~~~~~~~~~");
		}catch(Exception ee){};
		
	}
}

class cli
{
	public static void main(String[] a)
	{
		try{
		Socket c=new Socket("127.0.0.1",3000);
		DataInputStream i=new DataInputStream(c.getInputStream());
		System.out.println(i.readUTF());
		}catch(Exception e){}
	}
}
 
分享到:
评论

相关推荐

    Win32 API 函数大全使用详解 .rar_81I_API_Something About You_Win32 API_Wi

    8. **网络编程**:`WSAStartup`初始化网络套接字,`socket`创建套接字,`bind`绑定IP地址和端口,`connect`和`accept`处理客户端连接,`send`和`recv`发送和接收数据。 9. **文件和注册表操作**:`CreateFile`、`...

    AIO nginx C10K

    something about highest Asynchronous Performance development of Concurrent, may be the best docs you can find , thanks

    UPnP_Programming_Guide

    - **4.1.33** `UPNP_E_NOT_FOUND [-507]`: Signals that something could not be found. - **4.1.34** `UPNP_E_INTERNAL_ERROR [-911]`: Indicates an internal error within the SDK. ##### 4.2 Constants, ...

    Python程序设计(第二版).chm

    "And Now for Something Completely Different . . . Again" Signs of the Python Times Why This Edition? Major Changes in This Edition Using the Examples and Demos Conventions Used in This Book...

    图像处理程序大全 C++

    SOCKET m_socket; // 定义一个套接字 ///////////////////////////////////////////////////////////////////////////// // CMy002App initialization BOOL CMy002App::InitInstance() { // *** 判断程序是否已...

    ICS delphixe10源码版

    .\Samples\delphi\SocketDemos Delphi Win32/Win64 Socket sample applications (all Delphi versions) .\Samples\delphi\sslinternet Delphi Win32/Win64 SSL-enabled sample applications (all Delphi versions) ....

    php.ini-development

    they might mean something in the future. ; Directives following the section heading [PATH=/www/mysite] only ; apply to PHP files in the /www/mysite directory. Directives ; following the section ...

    Sakemail

    so Craig fixed it.- Warning: I‘ve put try/except in the TSakPOP.Connect and TSMTP.Connect function around the line FSocket.Open, so you will need to write something like: myPOP.Connect; if POPError ...

Global site tag (gtag.js) - Google Analytics