服务器端: import java.io.*;import .*;public class xin {ServerSocket mSS;Socket mSocket;static int port;public xin(){try{mSS = new ServerSocket(port);System.out.println("涂涂说创建了一个Server");System.
Server.py: '''
Created on 3月7日
@author: pangbin2415
'''import socketsock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # 生成socket对象sock.bind(('localhost', 8001))
#绑定主机ip和端口号sock.listen(5)while True:
connection,addr = sock.accept()
#接受客户端的连接
try:
connection.settimeout(5)
buf = connection.recv(1024)
if buf == 1:
connection.s/*使用Socket 通信实现 FTP 服务器端 程序*/#include "unp.h"#include #define SA
struct sockaddrint main(int argc, char *argv[]){
int
sock_fd, new_fd;
struct sockaddr_in
server_addr, client_addr;
intend('welcome to server!')
#向客户端发送一个字符串信息
else:
connection.send("Failed")
except socket.timeout:
#如果出现超时
print 'time out'
connection.close() Client.py '''Created on 3月7日@author: pangbin2415'''import socketimport timesock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)sock.connect(('localhost', 8001))time.sleep(2)sock.send('1')print sock.recv(1024)